QPushbutton用于发送toggled(bool)的checkable属性

  默认情况下checkable是不选中的,Button默认为触发按钮(trigger button),按下去马上弹起来。选中checkable后,Button变成切换按钮(toggle button),可以有两种状态,即按下和弹起。此时该按钮可以发射toggled(bool)信号,与槽函数setVisible(bool)结合,即可用于控件交替显示。
  下图中两个more按钮,上边是弹起状态,下边是按下状态:
在这里插入图片描述
  问题:I have the follwing code where moreButton is a QPushButton. When I toggle the button, nothing happens. Shouldn’t it show or hide secondaryGroupBox and tertiaryGroupBox?

QObject::connect ( moreButton, SIGNAL ( toggled ( bool ) ), secondaryGroupBox, SLOT ( setVisible ( bool ) ) );
QObject::connect ( moreButton, SIGNAL ( toggled ( bool ) ), tertiaryGroupBox, SLOT ( setVisible ( bool ) ) );

  回答:Most likely, your pushbutton is not checkable. Try moreButton->setCheckable(true), a non-checkable button never emits the toggled(bool) signal.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值