Cool_Coder
Cool_Coder

Reputation: 5083

Possible bug in QPushbutton?

I want to implement something similar to Ribbon UI found in MS Office 2007. I am using QPushbutton's along with QStacked Widget. When a QPushbutton is pressed corresponding widget from Stacked Widget is displayed. I want to implement in such way that when a PushButton is pressed down we should not be able to press it again except if some other QPushButton is pressed. So for the clicked() SLOT of my QPushButton I am calling this: button->setDown(true); in my 1st line. According to the documentation:

If this property is true, the button is pressed down. The signals pressed() and clicked() are not emitted if you set this property to true.

So when I click it at run time the button is shown as pressed down. Thats good! However the SIGNAL's are still emitted i.e. pressed() & clicked() are emitted. I have tried for the same property using different combinations of SIGNAL's & SLOT's. However its just the same. I am using Qt 4.8.1. What is going wrong here? Thank You.

Upvotes: 1

Views: 1043

Answers (2)

cppguy
cppguy

Reputation: 3723

set all the buttons to checkable and then read up on

http://qt-project.org/doc/qt-4.8/qbuttongroup.html

Upvotes: 0

Adriano Repetti
Adriano Repetti

Reputation: 67148

If you want to set the button visual appearance to pressed you can use the setDown() function. The documentation isn't very clear but:

If this property is true, the button is pressed down. The signals pressed() and clicked() are not emitted if you set this property to true.

It doesn't mean that that signals won't be emitted while the button is pressed but that they won't be emitted when you call setDown() (after all the button is enabled and a 2nd click may simply toggle its state).

What you can do is to check if the button is pressed (isDown()) inside your handler for clicked(). As alternative you may change the button to be checkable (with setCheckable())): 2nd click on the button will "close" it (if it's the behavior you need).

Upvotes: 3

Related Questions