Table Of Contents

Previous topic

QCommandLinkButton

Next topic

QWizardPage

QCheckBox

Synopsis

Functions

Signals

Detailed Description

The PySide.QtGui.QCheckBox widget provides a checkbox with a text label.

A PySide.QtGui.QCheckBox is an option button that can be switched on (checked) or off (unchecked). Checkboxes are typically used to represent features in an application that can be enabled or disabled without affecting others, but different types of behavior can be implemented. For example, a PySide.QtGui.QButtonGroup can be used to group check buttons logically, allowing exclusive checkboxes. However, PySide.QtGui.QButtonGroup does not provide any visual representation.

The image below further illustrates the differences between exclusive and non-exclusive checkboxes.

../../_images/checkboxes-exclusive.png ../../_images/checkboxes-non-exclusive.png

Whenever a checkbox is checked or cleared it emits the signal PySide.QtGui.QCheckBox.stateChanged() . Connect to this signal if you want to trigger an action each time the checkbox changes state. You can use PySide.QtGui.QAbstractButton.isChecked() to query whether or not a checkbox is checked.

In addition to the usual checked and unchecked states, PySide.QtGui.QCheckBox optionally provides a third state to indicate “no change”. This is useful whenever you need to give the user the option of neither checking nor unchecking a checkbox. If you need this third state, enable it with PySide.QtGui.QCheckBox.setTristate() , and use PySide.QtGui.QCheckBox.checkState() to query the current toggle state.

Just like PySide.QtGui.QPushButton , a checkbox displays text, and optionally a small icon. The icon is set with PySide.QtGui.QAbstractButton.setIcon() . The text can be set in the constructor or with PySide.QtGui.QAbstractButton.setText() . A shortcut key can be specified by preceding the preferred character with an ampersand. For example:

checkbox = QCheckBox("C&ase sensitive", self)

In this example the shortcut is Alt+A . See the QShortcut documentation for details (to display an actual ampersand, use ‘&&’).

Important inherited functions: PySide.QtGui.QAbstractButton.text() , PySide.QtGui.QAbstractButton.setText() , PySide.QtGui.QAbstractButton.text() , pixmap() , setPixmap() , accel() , setAccel() , isToggleButton() , PySide.QtGui.QAbstractButton.setDown() , PySide.QtGui.QAbstractButton.isDown() , isOn() , PySide.QtGui.QCheckBox.checkState() , PySide.QtGui.QAbstractButton.autoRepeat() , isExclusiveToggle(), PySide.QtGui.QAbstractButton.group() , PySide.QtGui.QAbstractButton.setAutoRepeat() , PySide.QtGui.QAbstractButton.toggle() , PySide.QtGui.QAbstractButton.pressed() , PySide.QtGui.QAbstractButton.released() , PySide.QtGui.QAbstractButton.clicked() , PySide.QtGui.QAbstractButton.toggled() , PySide.QtGui.QCheckBox.checkState() , and PySide.QtGui.QCheckBox.stateChanged() .

../../_images/macintosh-checkbox.png A checkbox shown in the Macintosh widget style .
../../_images/windows-checkbox.png A checkbox shown in the Windows XP widget style .
../../_images/plastique-checkbox.png A checkbox shown in the Plastique widget style .

See also

PySide.QtGui.QAbstractButton PySide.QtGui.QRadioButton GUI Design Handbook: Check Box

class PySide.QtGui.QCheckBox([parent=None])
class PySide.QtGui.QCheckBox(text[, parent=None])
Parameters:

Constructs a checkbox with the given parent , but with no text.

parent is passed on to the PySide.QtGui.QAbstractButton constructor.

Constructs a checkbox with the given parent and text .

parent is passed on to the PySide.QtGui.QAbstractButton constructor.

PySide.QtGui.QCheckBox.checkState()
Return type:PySide.QtCore.Qt.CheckState

Returns the check box’s check state. If you do not need tristate support, you can also use QAbstractButton.isChecked() which returns a boolean.

PySide.QtGui.QCheckBox.initStyleOption(option)
Parameters:optionPySide.QtGui.QStyleOptionButton

Initializes option with the values from this PySide.QtGui.QCheckBox . This method is useful for subclasses that require a PySide.QtGui.QStyleOptionButton , but do not want to fill in all the information themselves.

PySide.QtGui.QCheckBox.isTristate()
Return type:PySide.QtCore.bool

This property holds whether the checkbox is a tri-state checkbox.

The default is false; i.e. the checkbox has only two states.

PySide.QtGui.QCheckBox.setCheckState(state)
Parameters:statePySide.QtCore.Qt.CheckState
PySide.QtGui.QCheckBox.setTristate([y=true])
Parameters:yPySide.QtCore.bool

This property holds whether the checkbox is a tri-state checkbox.

The default is false; i.e. the checkbox has only two states.

PySide.QtGui.QCheckBox.stateChanged(arg__1)
Parameters:arg__1PySide.QtCore.int