pyqt4文档阅读(4.1):QCheckBox

本文档详细介绍了PyQt4中的QCheckBox控件,包括其属性、方法、Qt信号和状态管理。QCheckBox提供两种或三种状态(打勾、空白、正方形),并有一个`stateChanged`信号在状态改变时触发。此外,还讨论了快捷键、设置和检查状态的函数,以及与其他控件的交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本系列文章长期更新修改.


QCheckBox,就是一个打勾的控件.



属性:

Methods

  • __init__ (self, QWidget parent = None)
  • __init__ (self, QString text, QWidget parent = None)
  • Qt.CheckState checkState (self)
  • checkStateSet (self)
  • bool event (self, QEvent e)
  • bool hitButton (self, QPoint pos)
  • initStyleOption (self, QStyleOptionButton option)
  • bool isTristate (self)
  • mouseMoveEvent (self, QMouseEvent)
  • nextCheckState (self)
  • paintEvent (self, QPaintEvent)
  • setCheckState (self, Qt.CheckState state)
  • setTristate (self, bool y = True)
  • QSize sizeHint (self)

Qt Signals

  • void stateChanged (int)


详细分析:


1.主要设置

QCheckBox的主要设置是文本和icon,用法和QPushButton一样,参考QPushButton篇.

2.快捷键

QCheckBox的快捷键用法参考QPushButton篇.

3.打勾状态

QCheckBox默认有两种状态,打勾和空白,可以通过下面函数获取和设置:

  • bool isChecked (self)
  • setChecked (self, bool)
4.三状态

QCheckBox允许设置成三种状态,打勾,正方形,空白.文档对正方形的解释是"No change".

把属性tristate设置为true,则QCheckBox会变成3状态,相关函数如下:

  • bool isTristate (self)
  • setTristate (self, bool y = True)

这样的话,作为bool值的checked属性并不能表达三种状态,我们需要状态值checkState,它是一个枚举量.

  • Qt.CheckState checkState (self)
  • setCheckState (self, Qt.CheckState state)

枚举量描述isChecked()
Qt.Unchecked0空白false
Qt.PartiallyChecked1正方形true
Qt.Checked2打勾true

注意,二状态的QCheckBox也能使用checkState属性,它会在0和2之间变化.

5.信号

QCheckBox就一个特有信号,并且含义很清晰,就是当状态改变时激活,参数是checkState的值.

  • void stateChanged (int)
6.改变状态函数

QCheckBox提供了一个动作函数来改变状态.

2状态时,它会在空白和打勾之间改变,3状态时,则会在空白,正方形,打勾不断循环.

  • nextCheckState (self)

7.待续

bool hitButton (self, QPoint pos)


checkStateSet (self)


bool event (self, QEvent e)
initStyleOption (self, QStyleOptionButton option)
mouseMoveEvent (self, QMouseEvent)
paintEvent (self, QPaintEvent)
QSize sizeHint (self)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值