QCheckBox:如何区分用户引起的状态更改和以编程方式进行的更改?
我是否错过了某些东西,或者确实没有(就绪/内置)方法以编程方式更改 QCheckBox 的状态而不发出“void stateChanged ( int state )”信号?
无论是否调用“void setCheckState (Qt::CheckState state)”或用户通过 ui 更改状态,都会发出上述信号,并且不会像 QLineEdit 那样发出“stateEdited”信号。
因此,如果没有现成的方法来区分 QCheckBox 状态的编程更改和用户引起的更改,并且唯一的选择是子类化/添加“stateEdited”信号或摆弄“void QObject::blockSignals( bool block ) “,为什么一定要这样,即(在 Qt 中)是否存在(某种)不一致?
Do I miss something or there is really no (ready / built-in) way to programmatically change the state of a QCheckBox without emitting the "void stateChanged ( int state )" signal?
The above-mentioned signal is emitted regardless of whether "void setCheckState ( Qt::CheckState state )" was called or the user changed the state via the ui, and there is no "stateEdited" signal like with the QLineEdit.
So, if there is no ready way to differentiate between programmatic and user-induced changes to the state of the QCheckBox, and the only options are subclassing / adding the "stateEdited" signal or fiddling with "void QObject::blockSignals( bool block )", why does this have to be so, i.e., is it an (some sort of) inconsistency (in Qt)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只需要了解用户输入,请收听“
否则连接到”
或
If you only need to be informed of user input, listen to
Otherwise connect to
or
适用于所有信号和小部件的方法是将
setChecked()
调用包装在一对blockSignals()
调用中:或者,使用每个 Qt 程序员都会有的东西在他的工具箱中:
一个 RAII 类。用法:
编辑 2013-12-10: Qt 5.3 将内置 QSignalBlocker。
An approach that works for all signals and widgets is to wrap the calls to
setChecked()
in a pair ofblockSignals()
calls:or, with something every Qt programmer will have in his toolbox:
a RAII class. Usage:
EDIT 2013-12-10: Qt 5.3 will have QSignalBlocker built-in.
如果你想
使用 setCheckState 方法
。 PS我不明白什么意思
可能您应该阅读 信号和槽主题更仔细。
If you want to
use setCheckState method.
P.S. I do not understand what does it mean
Probably you should read Signals and Slots topic more carefully.