Toggling a QPushButton
Toggling a QPushButton
本文关键字:QPushButton Toggling 更新时间:2023-10-16
我有一个简单的GUI:
一个QPushButton,当点击时,将显示一个数字(比如11)(我使用一个QLCDnumber)。当再次点击时,将显示另一个数字(例如10)。
我的目标是使用QAbstractButton::toggle (bool checked)特性。
据我所知,一个正确的信号槽连接应该是这样的:
connect(ui.startstopButton, SIGNAL(toggled(bool)), thread, SLOT(start()));
(我另外使用线程,但它们不是问题)
我的问题:在我的信号槽语句中,我如何区分"按钮被切换"(checked = true)和"按钮未被切换"(checkked = false) ?
我使用像SIGNAL(toggled(bool = true))
, SIGNAL(toggled(bool checked = true))
或SIGNAL(toggled(true))
的变化,但都不工作。我总是得到调试器消息:
Object::connect: No such signal QPushButton::toggled(bool = true) in testthread.cpp:15
Object::connect: (sender name: 'startstopButton')
我已经启用了setCheckable
按钮
信号只是toggled(bool)
,接收端也将有一个bool参数:
connect(ui.startstopButton, SIGNAL(toggled(bool)), thread, SLOT(start(bool)));
这样切换信号发送的布尔值将被插槽接收。在slot函数中,您可以检查接收到的布尔值是否为真。
这里假设thread:start()是你实际编写的某个函数,如果不是,创建一个新槽来检查布尔值,然后启动线程。
connect(ui.startstopButton, SIGNAL(toggled(bool)), threadStarter, SLOT(start(bool)));
不能。相反,您可以将其传递到自定义槽:
void checkIt(bool checked) // This is a slot
{
}
// ...
connect(ui.startstopButton, SIGNAL(toggled(bool)), thread, SLOT(checkIt(bool)));
相关文章:
- 在单击 QPushButton 时调用带有参数的函数
- 按下 QPushbutton 时将文本保存到文件
- QProcess无法通过QPushButton执行终端线路命令
- 在两个类之间连接QPushButton
- QGraphicsScene 中的 QPushButton 需要双击而不是单击
- 如何在取消选择QCheckBox时禁用QPushButton
- 使用 QpushButton 切换显示在 QLabel 中的图像
- 如何从QPushButton检索图标
- QT QPushButton Press Event
- 如何将QPushButton放入小部件中的Qt3DWindow中?
- 如何释放QPushButton的焦点,这是QDialog的默认按钮
- QPushButton 错误在 QT5 下,同时推动在 macOS 上进入全屏
- 在按下Qpushbutton时做点什么
- 创建一个 2 行(不换行)的 QPushButton
- 设置QPUSHBUTTON的最小宽度,同时保持默认的最小尺寸行为
- 调用 'QGridLayout::addWidget(QPushButton, int&, int&) 时没有匹配函数
- 从QStringList为QPushButton制作指针
- qt如何连接QPushButton的2D数组并返回位置
- 如何在点击的QPushButton的位置画一个形状
- Toggling a QPushButton