Results 1 to 6 of 6

Thread: How can find which button is clicked.

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default How can find which button is clicked.

    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.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How can find which button is clicked.

    You can either use QSignalMapper, or get the emitter's handle using sender() call in the slot, I would prefer the first one.

  3. #3
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How can find which button is clicked.

    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.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How can find which button is clicked.

    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

  5. #5
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How can find which button is clicked.

    If you want to do something different for each button, this argues for having three different slots.

  6. #6
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How can find which button is clicked.

    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.

Similar Threads

  1. Replies: 4
    Last Post: 29th April 2011, 09:42
  2. How to get the clicked button handle?
    By Gokulnathvc in forum Newbie
    Replies: 1
    Last Post: 27th April 2011, 08:06
  3. button background color when it is clicked
    By navi1084 in forum Qt Programming
    Replies: 4
    Last Post: 9th December 2008, 15:02
  4. How to find which column clicked from a treeview.
    By mekos in forum Qt Programming
    Replies: 2
    Last Post: 4th August 2008, 16:44
  5. Replies: 17
    Last Post: 31st March 2006, 05:57

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.