PDA

View Full Version : How to distinguish the pushbutton clicked() signal source from many ?



yellowmat
25th January 2006, 17:04
Hi,

I Have many push buttons which can be clicked and I want to connect all clicked() signals of those buttons to only one slot processClick() ... how is it possible to distinguish which button has been clicked in my slot ?

I'm sure there is a way to avoid having a slot per clicked() signal (euh, I hope) but the problem is that I don't know how yet ... someone has an idea ?

Thanks in advance.

yogeshm02
25th January 2006, 17:15
You can use object name of the button, which you specified in the constructor, for that.

yellowmat
25th January 2006, 17:24
I have set the object name in the constructor and I guess that this parameter will help me to distinguish which push button has been clicked() into my processClick() custom slot ... but I still wonder about :
* how to pass get the object name parameter into my custom slot
* how to pass the object parameter to my custom slot

... hmm maybe should I need to subclass the QPushButton class in order to set a new signal clicked(const QString& objName) ans modify my custom slot as follow : processClick(const QString& objName)

Is that the way to a solution of my problem ? Or is there any other conventionnal way to resolve this issue ?

Codepoet
25th January 2006, 17:27
Warning: I don't know Qt 3 only 4...
Search in the docs for QObject::sender or QSignalMapper. Both should do what you want.

yellowmat
25th January 2006, 18:13
Yeap ... it works with QObject::sender(), I got the name of the object.

Thanks

yop
25th January 2006, 19:58
Why don't you consider a QButtonGroup (http://doc.trolltech.com/3.3/qbuttongroup.html) as an option?

yellowmat
27th January 2006, 11:11
Yop,

To answer your question, I first do not consider this option because ... I did not thougth about it :)

Finally, it is a question of design, I don't want to have line neither the title around my buttons.

yogeshm02
27th January 2006, 14:08
Finally, it is a question of design, I don't want to have line neither the title around my buttons.

QButtonGroup provides an abstract container into which button widgets can be placed. It does not provide a visual representation of this container (see QGroupBox for a container widget), but instead manages the states of each of the buttons in the group.

yogeshm02
27th January 2006, 14:11
QButtonGroup provides an abstract container into which button widgets can be placed. It does not provide a visual representation of this container (see QGroupBox for a container widget), but instead manages the states of each of the buttons in the group.

Sorry, above is true for Qt4 only.

But you can still omit border and title.

yellowmat
27th January 2006, 15:41
If I can omit the border line and title of my buttonGroup it may be interesting. But I also need to include a pictutre in the group because the graphical representation I want to have is as follow : a picture centered in my group and many buttons all around my picture.

I'll check this point in the afternoon.

yop
27th January 2006, 19:12
Sorry, above is true for Qt4 only.

But you can still omit border and title.
Or you can just hide() the QButtonGroup, and use this method to add the QButtons to it:

The button group is an invisible widget and the contained buttons have some other parent widget. In this usage, each button must be manually inserted, using insert(), into the button group and given an identifier.
Quote from the QButtonGroup docs ;)