How to distinguish the pushbutton clicked() signal source from many ?
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.
Re: How to distinguish the pushbutton clicked() signal source from many ?
You can use object name of the button, which you specified in the constructor, for that.
Re: How to distinguish the pushbutton clicked() signal source from many ?
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 ?
Re: How to distinguish the pushbutton clicked() signal source from many ?
Warning: I don't know Qt 3 only 4...
Search in the docs for QObject::sender or QSignalMapper. Both should do what you want.
Re: How to distinguish the pushbutton clicked() signal source from many ?
Yeap ... it works with QObject::sender(), I got the name of the object.
Thanks
Re: How to distinguish the pushbutton clicked() signal source from many ?
Why don't you consider a QButtonGroup as an option?
Re: How to distinguish the pushbutton clicked() signal source from many ?
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.
Re: How to distinguish the pushbutton clicked() signal source from many ?
Quote:
Originally Posted by yellowmat
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.
Re: How to distinguish the pushbutton clicked() signal source from many ?
Quote:
Originally Posted by yogeshm02
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.
Re: How to distinguish the pushbutton clicked() signal source from many ?
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.
Re: How to distinguish the pushbutton clicked() signal source from many ?
Quote:
Originally Posted by yogeshm02
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:
Quote:
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 ;)