本文整理汇总了Python中qtpy.QtWidgets.QCheckBox类的典型用法代码示例。如果您正苦于以下问题:Python QCheckBox类的具体用法?Python QCheckBox怎么用?Python QCheckBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QCheckBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_scedit
def create_scedit(self, text, option, default=NoDefault, tip=None,
without_layout=False):
label = QLabel(text)
clayout = ColorLayout(QColor(Qt.black), self)
clayout.lineedit.setMaximumWidth(80)
if tip is not None:
clayout.setToolTip(tip)
cb_bold = QCheckBox()
cb_bold.setIcon(ima.icon('bold'))
cb_bold.setToolTip(_("Bold"))
cb_italic = QCheckBox()
cb_italic.setIcon(ima.icon('italic'))
cb_italic.setToolTip(_("Italic"))
self.scedits[(clayout, cb_bold, cb_italic)] = (option, default)
if without_layout:
return label, clayout, cb_bold, cb_italic
layout = QHBoxLayout()
layout.addWidget(label)
layout.addLayout(clayout)
layout.addSpacing(10)
layout.addWidget(cb_bold)
layout.addWidget(cb_italic)
layout.addStretch(1)
layout.setContentsMargins(0, 0, 0, 0)
widget = QWidget(self)
widget.setLayout(layout)
return widget
示例2: __init__
def __init__(self, value, parent=None):
QGridLayout.__init__(self)
font = tuple_to_qfont(value)
assert font is not None
# Font family
self.family = QFontComboBox(parent)
self.family.setCurrentFont(font)
self.addWidget(self.family, 0, 0, 1, -1)
# Font size
self.size = QComboBox(parent)
self.size.setEditable(True)
sizelist = list(range(6, 12)) + list(range(12, 30, 2)) + [36, 48, 72]
size = font.pointSize()
if size not in sizelist:
sizelist.append(size)
sizelist.sort()
self.size.addItems([str(s) for s in sizelist])
self.size.setCurrentIndex(sizelist.index(size))
self.addWidget(self.size, 1, 0)
# Italic or not
self.italic = QCheckBox(_("Italic"), parent)
self.italic.setChecked(font.italic())
self.addWidget(self.italic, 1, 1)
# Bold or not
self.bold = QCheckBox(_("Bold"), parent)
self.bold.setChecked(font.bold())
self.addWidget(self.bold, 1, 2)
示例3: dialog
def dialog(title, text, icon, setting=None, default=None):
if not getattr(settings, setting.upper()):
return True
check = QCheckBox()
check.setText('Dont show this message again (can be reset via the preferences)')
info = QMessageBox()
info.setIcon(icon)
info.setText(title)
info.setInformativeText(text)
info.setCheckBox(check)
info.setStandardButtons(info.Cancel | info.Ok)
if default == 'Cancel':
info.setDefaultButton(info.Cancel)
result = info.exec_()
if result == info.Cancel:
return False
if check.isChecked():
setattr(settings, setting.upper(), False)
save_settings()
return True
示例4: create_controls
def create_controls(self):
"""
Create UI controls.
"""
vbox = QVBoxLayout()
form = QFormLayout()
self.num_angle = QDoubleSpinBox()
self.num_angle.setValue(0.0)
self.num_angle.setMinimum(-360)
self.num_angle.setMaximum(360)
form.addRow(tr("Angle:"), self.num_angle)
vbox.addLayout(form)
self.gbo_preview = QGroupBox(tr("Preview"))
self.gbo_preview.setCheckable(True)
self.gbo_preview.setChecked(False)
gbo_vbox = QVBoxLayout()
self.chk_grid = QCheckBox(tr("Grid"))
self.chk_grid.setChecked(False)
self.num_grid = QSpinBox()
self.num_grid.setValue(4)
self.num_grid.setMinimum(1)
self.num_grid.setEnabled(False)
self.chk_grid.toggled[bool].connect(self.num_grid.setEnabled)
gbo_vbox.addWidget(self.chk_grid)
gbo_vbox.addWidget(self.num_grid)
self.gbo_preview.setLayout(gbo_vbox)
vbox.addWidget(self.gbo_preview)
self.gbo_preview.toggled[bool].connect(self.set_preview)
self.gbo_output = QGroupBox(tr("Output"))
self.opt_new = QRadioButton(tr("New signal"))
self.opt_replace = QRadioButton(tr("In place"))
self.opt_new.setChecked(True)
gbo_vbox2 = QVBoxLayout()
gbo_vbox2.addWidget(self.opt_new)
gbo_vbox2.addWidget(self.opt_replace)
self.gbo_output.setLayout(gbo_vbox2)
vbox.addWidget(self.gbo_output)
self.chk_reshape = QCheckBox(tr("Resize to fit"))
self.chk_reshape.setChecked(False)
vbox.addWidget(self.chk_reshape)
self.btn_ok = QPushButton(tr("&OK"))
self.btn_ok.setDefault(True)
self.btn_ok.clicked.connect(self.accept)
self.btn_cancel = QPushButton(tr("&Cancel"))
self.btn_cancel.clicked.connect(self.reject)
hbox = QHBoxLayout()
hbox.addWidget(self.btn_ok)
hbox.addWidget(self.btn_cancel)
vbox.addLayout(hbox)
vbox.addStretch(1)
self.setLayout(vbox)
示例5: MovieArgsPrompt
class MovieArgsPrompt(QtWidgets.QWidget):
def __init__(self, parent=None):
super(MovieArgsPrompt, self).__init__(parent)
self.create_controls()
def create_controls(self):
self.num_fps = QtWidgets.QDoubleSpinBox()
self.num_fps.setValue(15.0)
self.num_fps.setMinimum(0.001)
self.edt_fname = QLineEdit()
self.btn_browse = QtWidgets.QPushButton("...")
self.num_dpi = QtWidgets.QSpinBox()
self.num_dpi.setValue(72)
self.num_dpi.setMinimum(1)
self.num_dpi.setMaximum(10000)
self.chk_axes = QCheckBox("Axes")
self.chk_colorbar = QCheckBox("Colorbar")
# codec = mpl.rcParams['animation.codec']
codec = 'h264'
self.edt_codec = QLineEdit(codec)
self.edt_extra = QLineEdit("-preset veryslow -crf 0")
# TODO: Use QCompleter or QComboBox for codecs
# TODO: Use QCompleter for 'extra' history
# TODO: Bitrate and/or quality slider
self.chk_verbose = QCheckBox("Verbose")
try:
sys.stdout.fileno()
except:
self.chk_verbose.setEnabled(False)
self.chk_verbose.setToolTip("Verbose output does not work with " +
"internal console.")
frm = QtWidgets.QFormLayout()
frm.addRow(tr("FPS:"), self.num_fps)
frm.addRow(tr("DPI:"), self.num_dpi)
frm.addRow(tr("Codec:"), self.edt_codec)
frm.addRow(tr("Extra args:"), self.edt_extra)
frm.addRow(self.chk_axes, self.chk_colorbar)
hbox = QtWidgets.QHBoxLayout()
hbox.addWidget(self.edt_fname)
hbox.addWidget(self.btn_browse)
frm.addRow(tr("File:"), hbox)
frm.addRow("", self.chk_verbose)
self.setLayout(frm)
示例6: __init__
def __init__(self, parent):
QFileDialog.__init__(self, parent)
self.setFileMode(QFileDialog.AnyFile)
self.setAcceptMode(QFileDialog.AcceptSave)
# Widgets
self._chk_tight = QCheckBox('Tight layout')
self._txt_dpi = QSpinBox()
self._txt_dpi.setRange(1, 10000)
self._txt_dpi.setSingleStep(50)
self._txt_dpi.setSuffix('dpi')
self._txt_dpi.setValue(100)
# Layouts
layout = self.layout()
lyt_extras = QHBoxLayout()
lyt_extras.addWidget(QLabel('Extra options'))
lyt_extras.addWidget(self._chk_tight)
lyt_extras.addWidget(QLabel('Resolution'))
lyt_extras.addWidget(self._txt_dpi)
layout.addLayout(lyt_extras, layout.rowCount(), 0, 1, layout.columnCount())
self.setLayout(layout)
示例7: create_checkbox
def create_checkbox(self, text, option, default=NoDefault,
tip=None, msg_warning=None, msg_info=None,
msg_if_enabled=False):
checkbox = QCheckBox(text)
if tip is not None:
checkbox.setToolTip(tip)
self.checkboxes[checkbox] = (option, default)
if msg_warning is not None or msg_info is not None:
def show_message(is_checked=False):
if is_checked or not msg_if_enabled:
if msg_warning is not None:
QMessageBox.warning(self, self.get_name(),
msg_warning, QMessageBox.Ok)
if msg_info is not None:
QMessageBox.information(self, self.get_name(),
msg_info, QMessageBox.Ok)
checkbox.clicked.connect(show_message)
return checkbox
示例8: MessageCheckBox
class MessageCheckBox(QMessageBox):
"""
A QMessageBox derived widget that includes a QCheckBox aligned to the right
under the message and on top of the buttons.
"""
def __init__(self, *args, **kwargs):
super(MessageCheckBox, self).__init__(*args, **kwargs)
self._checkbox = QCheckBox()
# Set layout to include checkbox
size = 9
check_layout = QVBoxLayout()
check_layout.addItem(QSpacerItem(size, size))
check_layout.addWidget(self._checkbox, 0, Qt.AlignRight)
check_layout.addItem(QSpacerItem(size, size))
# Access the Layout of the MessageBox to add the Checkbox
layout = self.layout()
if PYQT5:
layout.addLayout(check_layout, 1, 2)
else:
layout.addLayout(check_layout, 1, 1)
# --- Public API
# Methods to access the checkbox
def is_checked(self):
return self._checkbox.isChecked()
def set_checked(self, value):
return self._checkbox.setChecked(value)
def set_check_visible(self, value):
self._checkbox.setVisible(value)
def is_check_visible(self):
self._checkbox.isVisible()
def checkbox_text(self):
self._checkbox.text()
def set_checkbox_text(self, text):
self._checkbox.setText(text)
示例9: setup_and_check
def setup_and_check(self, data, title=''):
"""
Setup DataFrameEditor:
return False if data is not supported, True otherwise
"""
self.layout = QGridLayout()
self.setLayout(self.layout)
self.setWindowIcon(ima.icon('arredit'))
if title:
title = to_text_string(title) + " - %s" % data.__class__.__name__
else:
title = _("%s editor") % data.__class__.__name__
if isinstance(data, Series):
self.is_series = True
data = data.to_frame()
self.setWindowTitle(title)
self.resize(600, 500)
self.dataModel = DataFrameModel(data, parent=self)
self.dataTable = DataFrameView(self, self.dataModel)
self.layout.addWidget(self.dataTable)
self.setLayout(self.layout)
self.setMinimumSize(400, 300)
# Make the dialog act as a window
self.setWindowFlags(Qt.Window)
btn_layout = QHBoxLayout()
btn = QPushButton(_("Format"))
# disable format button for int type
btn_layout.addWidget(btn)
btn.clicked.connect(self.change_format)
btn = QPushButton(_('Resize'))
btn_layout.addWidget(btn)
btn.clicked.connect(self.resize_to_contents)
bgcolor = QCheckBox(_('Background color'))
bgcolor.setChecked(self.dataModel.bgcolor_enabled)
bgcolor.setEnabled(self.dataModel.bgcolor_enabled)
bgcolor.stateChanged.connect(self.change_bgcolor_enable)
btn_layout.addWidget(bgcolor)
self.bgcolor_global = QCheckBox(_('Column min/max'))
self.bgcolor_global.setChecked(self.dataModel.colum_avg_enabled)
self.bgcolor_global.setEnabled(not self.is_series and
self.dataModel.bgcolor_enabled)
self.bgcolor_global.stateChanged.connect(self.dataModel.colum_avg)
btn_layout.addWidget(self.bgcolor_global)
btn_layout.addStretch()
bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
bbox.accepted.connect(self.accept)
bbox.rejected.connect(self.reject)
btn_layout.addWidget(bbox)
self.layout.addLayout(btn_layout, 2, 0)
return True
示例10: create_controls
def create_controls(self):
self.txt_name = QLineEdit()
self.chk_menu = QCheckBox(tr("Menu entry"))
self.chk_menu.setChecked(True)
self.chk_toolbar = QCheckBox(tr("Toolbar button"))
self.chk_toolbar.setChecked(True)
self.txt_category = QLineEdit()
self.chk_icon = QCheckBox()
self.chk_toolbar.setChecked(False)
self.txt_iconpath = QLineEdit()
self.btn_browse_icon = QPushButton("...")
self.txt_iconpath.setEnabled(False)
self.btn_browse_icon.setEnabled(False)
btns = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
QtCore.Qt.Horizontal)
self.chk_menu.toggled.connect(self.checks_changed)
self.chk_toolbar.toggled.connect(self.checks_changed)
self.chk_icon.toggled.connect(self.checks_changed)
self.btn_browse_icon.clicked.connect(self.browse_icon)
btns.accepted.connect(self.accept)
btns.rejected.connect(self.reject)
hbox = QHBoxLayout()
for w in [self.chk_icon, self.txt_iconpath, self.btn_browse_icon]:
hbox.addWidget(w)
form = QFormLayout()
form.addRow(tr("Name"), self.txt_name)
form.addRow(self.chk_menu, self.chk_toolbar)
form.addRow(tr("Category"), self.txt_category)
form.addRow(tr("Icon"), hbox)
vbox = QVBoxLayout(self)
vbox.addLayout(form)
vbox.addWidget(btns)
self.setLayout(vbox)
示例11: __init__
def __init__(self, parent, data, readonly=False,
xlabels=None, ylabels=None):
QWidget.__init__(self, parent)
self.data = data
self.old_data_shape = None
if len(self.data.shape) == 1:
self.old_data_shape = self.data.shape
self.data.shape = (self.data.shape[0], 1)
elif len(self.data.shape) == 0:
self.old_data_shape = self.data.shape
self.data.shape = (1, 1)
format = SUPPORTED_FORMATS.get(data.dtype.name, '%s')
self.model = ArrayModel(self.data, format=format, xlabels=xlabels,
ylabels=ylabels, readonly=readonly, parent=self)
self.view = ArrayView(self, self.model, data.dtype, data.shape)
btn_layout = QHBoxLayout()
btn_layout.setAlignment(Qt.AlignLeft)
btn = QPushButton(_( "Format"))
# disable format button for int type
btn.setEnabled(is_float(data.dtype))
btn_layout.addWidget(btn)
btn.clicked.connect(self.change_format)
btn = QPushButton(_( "Resize"))
btn_layout.addWidget(btn)
btn.clicked.connect(self.view.resize_to_contents)
bgcolor = QCheckBox(_( 'Background color'))
bgcolor.setChecked(self.model.bgcolor_enabled)
bgcolor.setEnabled(self.model.bgcolor_enabled)
bgcolor.stateChanged.connect(self.model.bgcolor)
btn_layout.addWidget(bgcolor)
layout = QVBoxLayout()
layout.addWidget(self.view)
layout.addLayout(btn_layout)
self.setLayout(layout)
示例12: __init__
def __init__(self, *args, **kwargs):
super(MessageCheckBox, self).__init__(*args, **kwargs)
self._checkbox = QCheckBox()
# Set layout to include checkbox
size = 9
check_layout = QVBoxLayout()
check_layout.addItem(QSpacerItem(size, size))
check_layout.addWidget(self._checkbox, 0, Qt.AlignRight)
check_layout.addItem(QSpacerItem(size, size))
# Access the Layout of the MessageBox to add the Checkbox
layout = self.layout()
layout.addLayout(check_layout, 1, 1)
示例13: set_check_box
def set_check_box(self, row, col, state):
""" function to add a new select checkbox to a cell in a table row
won't add a new checkbox if one already exists
"""
# Check input
assert isinstance(state, bool)
# Check if cellWidget exists
if self.cellWidget(row, col):
# existing: just set the value
self.cellWidget(row, col).setChecked(state)
else:
# case to add checkbox
checkbox = QCheckBox()
checkbox.setText('')
checkbox.setChecked(state)
# Adding a widget which will be inserted into the table cell
# then centering the checkbox within this widget which in turn,
# centers it within the table column :-)
self.setCellWidget(row, col, checkbox)
# END-IF-ELSE
return
示例14: __init__
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.setWindowTitle(_("Spyder internal error"))
self.setModal(True)
# To save the traceback sent to the internal console
self.error_traceback = ""
# Dialog main label
self.main_label = QLabel(
_("""<b>Spyder has encountered an internal problem</b><hr>
Please enter below a step-by-step description of
your problem (in English). Issue reports without
a clear way to reproduce them will be closed.
<br><br>
<b>Note</b>: You need a Github account for this.
"""))
self.main_label.setWordWrap(True)
self.main_label.setAlignment(Qt.AlignJustify)
# Field to input the description of the problem
self.input_description = DescriptionWidget(self)
# Only allow to submit to Github if we have a long enough description
self.input_description.textChanged.connect(self._description_changed)
# Widget to show errors
self.details = ShowErrorWidget(self)
self.details.set_pythonshell_font(get_font())
self.details.hide()
# Label to show missing chars
self.initial_chars = len(self.input_description.toPlainText())
self.chars_label = QLabel(_("Enter at least {} "
"characters".format(MIN_CHARS)))
# Checkbox to dismiss future errors
self.dismiss_box = QCheckBox()
self.dismiss_box.setText(_("Don't show again during this session"))
# Labels layout
labels_layout = QHBoxLayout()
labels_layout.addWidget(self.chars_label)
labels_layout.addWidget(self.dismiss_box, 0, Qt.AlignRight)
# Dialog buttons
self.submit_btn = QPushButton(_('Submit to Github'))
self.submit_btn.setEnabled(False)
self.submit_btn.clicked.connect(self._submit_to_github)
self.details_btn = QPushButton(_('Show details'))
self.details_btn.clicked.connect(self._show_details)
self.close_btn = QPushButton(_('Close'))
# Buttons layout
buttons_layout = QHBoxLayout()
buttons_layout.addWidget(self.submit_btn)
buttons_layout.addWidget(self.details_btn)
buttons_layout.addWidget(self.close_btn)
# Main layout
vlayout = QVBoxLayout()
vlayout.addWidget(self.main_label)
vlayout.addWidget(self.input_description)
vlayout.addWidget(self.details)
vlayout.addLayout(labels_layout)
vlayout.addLayout(buttons_layout)
self.setLayout(vlayout)
self.resize(600, 420)
self.input_description.setFocus()
示例15: SpyderErrorDialog
class SpyderErrorDialog(QDialog):
"""Custom error dialog for error reporting."""
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.setWindowTitle(_("Spyder internal error"))
self.setModal(True)
# To save the traceback sent to the internal console
self.error_traceback = ""
# Dialog main label
self.main_label = QLabel(
_("""<b>Spyder has encountered an internal problem</b><hr>
Please enter below a step-by-step description of
your problem (in English). Issue reports without
a clear way to reproduce them will be closed.
<br><br>
<b>Note</b>: You need a Github account for this.
"""))
self.main_label.setWordWrap(True)
self.main_label.setAlignment(Qt.AlignJustify)
# Field to input the description of the problem
self.input_description = DescriptionWidget(self)
# Only allow to submit to Github if we have a long enough description
self.input_description.textChanged.connect(self._description_changed)
# Widget to show errors
self.details = ShowErrorWidget(self)
self.details.set_pythonshell_font(get_font())
self.details.hide()
# Label to show missing chars
self.initial_chars = len(self.input_description.toPlainText())
self.chars_label = QLabel(_("Enter at least {} "
"characters".format(MIN_CHARS)))
# Checkbox to dismiss future errors
self.dismiss_box = QCheckBox()
self.dismiss_box.setText(_("Don't show again during this session"))
# Labels layout
labels_layout = QHBoxLayout()
labels_layout.addWidget(self.chars_label)
labels_layout.addWidget(self.dismiss_box, 0, Qt.AlignRight)
# Dialog buttons
self.submit_btn = QPushButton(_('Submit to Github'))
self.submit_btn.setEnabled(False)
self.submit_btn.clicked.connect(self._submit_to_github)
self.details_btn = QPushButton(_('Show details'))
self.details_btn.clicked.connect(self._show_details)
self.close_btn = QPushButton(_('Close'))
# Buttons layout
buttons_layout = QHBoxLayout()
buttons_layout.addWidget(self.submit_btn)
buttons_layout.addWidget(self.details_btn)
buttons_layout.addWidget(self.close_btn)
# Main layout
vlayout = QVBoxLayout()
vlayout.addWidget(self.main_label)
vlayout.addWidget(self.input_description)
vlayout.addWidget(self.details)
vlayout.addLayout(labels_layout)
vlayout.addLayout(buttons_layout)
self.setLayout(vlayout)
self.resize(600, 420)
self.input_description.setFocus()
def _submit_to_github(self):
"""Action to take when pressing the submit button."""
main = self.parent().main
# Getting description and traceback
description = self.input_description.toPlainText()
traceback = self.error_traceback[:-1] # Remove last eol
# Render issue
issue_text = main.render_issue(description=description,
traceback=traceback)
# Copy issue to clipboard
QApplication.clipboard().setText(issue_text)
# Submit issue to Github
issue_body=("<!--- "
"Please paste the contents of your clipboard "
"below to complete reporting your problem. "
"--->\n\n")
main.report_issue(body=issue_body,
title="Automatic error report")
def append_traceback(self, text):
#.........这里部分代码省略.........