• PySide 模块
  • PySide.QtGui
  • 内容表

    上一话题

    QCommandLinkButton

    下一话题

    QWizardPage

    QCheckBox

    概要

    函数

    信号

    详细描述

    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.

    就像 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)
    										

    在此范例中快捷方式是 Alt+A 。见 QShortcut documentation for details (to display an actual ampersand, use ‘&&').

    重要继承函数: 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() ,和 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 .

    另请参阅

    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 被传递给 PySide.QtGui.QAbstractButton 构造函数。

    Constructs a checkbox with the given parent and text .

    parent 被传递给 PySide.QtGui.QAbstractButton 构造函数。

    PySide.QtGui.QCheckBox. checkState ( )
    返回类型: 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.setCheckState() Qt.CheckState

    PySide.QtGui.QCheckBox. initStyleOption ( option )
    参数: option PySide.QtGui.QStyleOptionButton

    初始化 option 采用值来自此 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 ( )
    返回类型: 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 )
    参数: state PySide.QtCore.Qt.CheckState
    PySide.QtGui.QCheckBox. setTristate ( [ y=true ] )
    参数: y 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. stateChanged ( arg__1 )
    参数: arg__1 PySide.QtCore.int