Home · All Classes · Modules

QCheckBox Class Reference
[QtGui module]

The QCheckBox widget provides a checkbox with a text label. More...

Inherits QAbstractButton.

Methods

Qt Signals


Detailed 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, but different types of behavior can be implemented.

A QButtonGroup can be used to group check buttons visually.

Whenever a checkbox is checked or cleared it emits the signal stateChanged(). 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 '&&').

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

Screenshot of a Macintosh style checkbox A checkbox shown in the Macintosh widget style.
Screenshot of a Windows XP style checkbox A checkbox shown in the Windows XP widget style.
Screenshot of a Plastique style checkbox A checkbox shown in the Plastique widget style.


See also QAbstractButton, QRadioButton, and GUI Design Handbook: Check Box.


Method Documentation

QCheckBox.__init__ (self, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

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

The parent argument is passed on to the QAbstractButton constructor.

QCheckBox.__init__ (self, QString text, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a checkbox with the given parent and text.

The parent argument is passed on to the QAbstractButton constructor.

Qt.CheckState QCheckBox.checkState (self)

Returns the check box's check state.

See also setCheckState() and Qt.CheckState.

QCheckBox.checkStateSet (self)

bool QCheckBox.event (self, QEvent e)

bool QCheckBox.hitButton (self, QPoint pos)

QCheckBox.initStyleOption (self, QStyleOptionButton option)

Initialize option with the values from this QCheckBox. This method is useful for subclasses when they need a QStyleOptionButton, but don't want to fill in all the information themselves.

See also QStyleOption.initFrom().

bool QCheckBox.isTristate (self)

QCheckBox.mouseMoveEvent (self, QMouseEvent)

QCheckBox.nextCheckState (self)

QCheckBox.paintEvent (self, QPaintEvent)

QCheckBox.setCheckState (self, Qt.CheckState state)

Sets the check box's check state to state.

See also checkState() and Qt.CheckState.

QCheckBox.setTristate (self, bool y = True)

QSize QCheckBox.sizeHint (self)


Qt Signal Documentation

void stateChanged (int)

This signal is emitted whenever the check box's state changes, i.e. whenever the user checks or unchecks it.

state contains the check box's new ToggleState.


PyQt 4.3.1 for X11Copyright © Riverbank Computing Ltd and Trolltech AS 2007Qt 4.3.0