Results 1 to 11 of 11

Thread: How to distinguish the pushbutton clicked() signal source from many ?

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default 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.

  2. #2
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  3. #3
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default 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 ?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    85
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  5. #5
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default 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

  6. #6
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to distinguish the pushbutton clicked() signal source from many ?

    Why don't you consider a QButtonGroup as an option?

  7. #7
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default 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.

  8. #8
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  9. #9
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  10. #10
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default 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.

  11. #11
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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:
    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

Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 08:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 08:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.