您的位置:首页 > 其它

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

2015-07-04 16:07 302 查看
默认状况下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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: