Table Of Contents

Previous topic


Next topic



Inheritance diagram of QCheckBox




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.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])

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.

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.


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.

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.


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

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