QCheckBox Class
QCheckBox 提供一个带有文本标签的复选框. 更多...
头文件: | #include <QCheckBox> |
qmake: | QT += widgets |
基类: | QAbstractButton |
属性
- tristate : bool
- 11 个属性继承自 QAbstractButton
- 59 个属性继承自 QWidget
- 1 个属性继承自 QObject
公有函数
QCheckBox(QWidget *parent = Q_NULLPTR) | |
QCheckBox(const QString &text, QWidget *parent = Q_NULLPTR) | |
~QCheckBox() | |
Qt::CheckState | checkState() const |
bool | isTristate() const |
void | setCheckState(Qt::CheckState state) |
void | setTristate(bool y = true) |
重新实现的公有函数
virtual QSize | minimumSizeHint() const |
virtual QSize | sizeHint() const |
- 21 个公有函数继承自 QAbstractButton
- 214 个公有函数继承自 QWidget
- 32 个公有函数继承自 QObject
- 14 个公有函数继承自 QPaintDevice
信号
void | stateChanged(int state) |
- 4 个信号继承自 QAbstractButton
- 3 个信号继承自 QWidget
- 2 个信号继承自 QObject
受保护的函数
void | initStyleOption(QStyleOptionButton *option) const |
重新实现的受保护函数
virtual void | checkStateSet() |
virtual bool | event(QEvent *e) |
virtual bool | hitButton(const QPoint &pos) const |
virtual void | mouseMoveEvent(QMouseEvent *e) |
virtual void | nextCheckState() |
virtual void | paintEvent(QPaintEvent *) |
- 14 个受保护的函数继承自 QAbstractButton
- 35 个受保护的函数继承自 QWidget
- 9 个受保护的函数继承自 QObject
- 1 个受保护的函数继承自 QPaintDevice
其他继承的成员
- 5 个公有槽函数继承自 QAbstractButton
- 19 个公有槽函数继承自 QWidget
- 1 个公有槽函数继承自 QObject
- 1 个公有变量继承自 QObject
- 5 个静态公有成员继承自 QWidget
- 10 个静态公有成员继承自 QObject
- 1 个受保护的槽函数继承自 QWidget
- 2 个受保护的变量继承自 QObject
- 1 protected type inherited from QPaintDevice
详细描述
QCheckBox 提供一个带有文本标签的复选框.
QCheckBox 是一个可以打开(选中)或关闭(未选中)的选择按钮. 复选框表示应用程序中可以开启或禁用, 不影响其他widget的特性. 例如, 在逻辑上, 使用QButtonGroup 对复选框分组, 实现单独互斥的复选框. 然而, QButtonGroup 不提供任何可视化显示.
下图展示互斥和非互斥复选框之间的区别.
![]() | ![]() |
当复选框被选中或清除选中状态时, 复选框发送信号 stateChanged(). 如果你想在复选框每次状态更改时触发一个动作, 你可以连接这个信号. 你可以使用 isChecked() 查询复选框是否选中.
除了选中和未选中状态, QCheckBox 提供第三种状态: "no change". 这个状态给用户提供一个既不选中也不取消选中的场景. 如果你需要使用地三种状态, 调用 setTristate()开启它, 调用 checkState() 查询当前切换状态.
类似 QPushButton, 复选框可以显示文本及可选的小图标. 调用 setIcon()设置图标. 采用构造函数传值或调用 setText()设置文本. 快捷键也是通过前缀&设置. 例如:
QCheckBox *checkbox = new QCheckBox("C&ase sensitive", this);
上述示例中, 快捷键是 Alt+A. 详见 QShortcut 文档. 使用'&&'显示&.
重要的继承函数: text(), setText(), text(), pixmap(), setPixmap(), accel(), setAccel(), isToggleButton(), setDown(), isDown(), isOn(), checkState(), autoRepeat(), isExclusiveToggle(), group(), setAutoRepeat(), toggle(), pressed(), released(), clicked(), toggled(), checkState(), and stateChanged().
![]() | A checkbox shown in the Macintosh widget style. |
![]() | A checkbox shown in the Windows Vista widget style. |
![]() | A checkbox shown in the Fusion widget style. |
参见 QAbstractButton, QRadioButton, and GUI Design Handbook: Check Box.
属性
tristate : bool
复选框是否为三态复选框
默认是false, 即., 复选框只有两种状态.
访问函数:
bool | isTristate() const |
void | setTristate(bool y = true) |
成员函数
QCheckBox::QCheckBox(QWidget *parent = Q_NULLPTR)
Constructs a checkbox with the given parent, but with no text.
parent is passed on to the QAbstractButton constructor.
QCheckBox::QCheckBox(const QString &text, QWidget *parent = Q_NULLPTR)
Constructs a checkbox with the given parent and text.
parent is passed on to the QAbstractButton constructor.
QCheckBox::~QCheckBox()
Destructor.
Qt::CheckState QCheckBox::checkState() const
Returns the checkbox's check state. If you do not need tristate support, you can also use QAbstractButton::isChecked(), which returns a boolean.
参见 setCheckState() and Qt::CheckState.
[virtual protected]
void QCheckBox::checkStateSet()
重新实现 QAbstractButton::checkStateSet().
[virtual protected]
bool QCheckBox::event(QEvent *e)
重新实现 QObject::event().
[virtual protected]
bool QCheckBox::hitButton(const QPoint &pos) const
重新实现 QAbstractButton::hitButton().
[protected]
void QCheckBox::initStyleOption(QStyleOptionButton *option) const
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.
参见 QStyleOption::initFrom().
[virtual]
QSize QCheckBox::minimumSizeHint() const
重新实现 QWidget::minimumSizeHint().
[virtual protected]
void QCheckBox::mouseMoveEvent(QMouseEvent *e)
重新实现 QWidget::mouseMoveEvent().
[virtual protected]
void QCheckBox::nextCheckState()
重新实现 QAbstractButton::nextCheckState().
[virtual protected]
void QCheckBox::paintEvent(QPaintEvent *)
重新实现 QWidget::paintEvent().
void QCheckBox::setCheckState(Qt::CheckState state)
Sets the checkbox's check state to state. If you do not need tristate support, you can also use QAbstractButton::setChecked(), which takes a boolean.
参见 checkState() and Qt::CheckState.
[virtual]
QSize QCheckBox::sizeHint() const
重新实现 QWidget::sizeHint().
[signal]
void QCheckBox::stateChanged(int state)
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 Qt::CheckState.