QCheckBox — PyQt Documentation v6.9.0 (original) (raw)
PyQt6.QtWidgets.QCheckBox
Inherits from QAbstractButton.
Description¶
The QCheckBox widget provides a checkbox with a text label.
A 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. Different types of behavior can be implemented. For example, a QButtonGroup can be used to group check buttons logically, allowing exclusive checkboxes. However, QButtonGroup does not provide any visual representation.
The image below further illustrates the differences between exclusive and non-exclusive checkboxes.
![]() |
![]() |
---|
Whenever a checkbox is checked or cleared, it emits the signal checkStateChanged. Connect to this signal if you want to trigger an action each time the checkbox changes state. You can use isChecked() to query whether or not a checkbox is checked.
In addition to the usual checked and unchecked states, 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 setTristate(), and use checkState() to query the current toggle state.
Just like QPushButton, a checkbox displays text, and optionally a small icon. The icon is set with setIcon(). The text can be set in the constructor or with setText(). A shortcut key can be specified by preceding the preferred character with an ampersand. For example:
QCheckBox *checkbox = new QCheckBox("C&ase sensitive", this);
In this example, the shortcut is Alt+A. See the QShortcut documentation for details. To display an actual ampersand, use ‘&&’.
Methods¶
__init__(parent: QWidget = None)
Constructs a checkbox with the given parent, but with no text.
parent is passed on to the QAbstractButton constructor.
__init__(Optional[str], parent: QWidget = None)
Constructs a checkbox with the given parent and text.
parent is passed on to the QAbstractButton constructor.
checkState() → CheckState
Returns the checkbox’s check state. If you do not need tristate support, you can also use isChecked(), which returns a boolean.
checkStateSet()
TODO
event(QEvent) → bool
TODO
hitButton(QPoint) → bool
TODO
initStyleOption(QStyleOptionButton)
Initializes option with the values from this QCheckBox. This method is useful for subclasses that require a QStyleOptionButton, but do not want to fill in all the information themselves.
isTristate() → bool
TODO
minimumSizeHint() → QSize
TODO
mouseMoveEvent(QMouseEvent)
TODO
nextCheckState()
TODO
paintEvent(QPaintEvent)
TODO
setCheckState(CheckState)
Sets the checkbox’s check state to state. If you do not need tristate support, you can also use setChecked(), which takes a boolean.
setTristate(on: bool = True)
sizeHint() → QSize
TODO
Signals¶
checkStateChanged(CheckState)
This signal is emitted whenever the checkbox’s state changes, i.e., whenever the user checks or unchecks it.
state contains the checkbox’s new CheckState.
stateChanged(int)
Use checkStateChanged(CheckState) instead.
This signal is emitted whenever the checkbox’s state changes, i.e., whenever the user checks or unchecks it.
state contains the checkbox’s new CheckState.