PDA

View Full Version : How can find which button is clicked.



Niamita
27th June 2011, 05:44
Hi
How i can identify which button is clicked. I have three buttons connected to the same slot and in this slot i want to handle all three buttons difeerently. isClicked() something like this can solve my problem but i have not find this property.
How i can handle buttons then , i change the background color on clicking and i want that this remain untill another button is not clicked.

Santosh Reddy
27th June 2011, 05:58
You can either use QSignalMapper, or get the emitter's handle using sender() call in the slot, I would prefer the first one.

Niamita
27th June 2011, 06:05
Thanks for reply but i have solve the problem.
But the background color is not remaining untill another button is clicked. How should do it.

Santosh Reddy
27th June 2011, 06:14
But the background color is not remaining untill another button is clicked. How should do it.
It's not clear what to you said, but I guess you may changing the color some were else, or the slots are being called again

SixDegrees
27th June 2011, 07:35
If you want to do something different for each button, this argues for having three different slots.

Berryblue031
27th June 2011, 14:35
If you have 3 buttons and each one changes the background to a different colour this sounds like a good situation to put the buttons in a QButtonGroup. The QButtonGroup::clicked signal passes a pointer or id to let you know which button was clicked.
http://doc.qt.nokia.com/4.7/qbuttongroup.html

You can add buttons to a QButtongroup via the designer by having all your buttons selected at once and then right clicking.