Results 1 to 4 of 4

Thread: QPushButton Icon Image

  1. #1
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default QPushButton Icon Image

    Hello Again..
    I have a QPushButton, and I have an icon image on it. I am trying to change the image when the button is release.
    Pressed = Image 1
    Released = Image 2 = normal state
    I have tried many combinations of QIcon On/Off Active/Disabled, but I cannot seem to get it working. The button is not a toggle, just a push and release button.
    Thanks

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QPushButton Icon Image

    Take a look at QWidget::mouseReleaseEvent() and QWidget::mousePressEvent(). You can subclass QPushButton and re-implement those methods to change the icon to the appropriate one.

  3. The following user says thank you to JimDaniel for this useful post:

    QbelcorT (16th March 2009)

  4. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushButton Icon Image

    Quote Originally Posted by JimDaniel View Post
    Take a look at QWidget::mouseReleaseEvent() and QWidget::mousePressEvent(). You can subclass QPushButton and re-implement those methods to change the icon to the appropriate one.
    or install event filter and catch QMouseEvent.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #4
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QPushButton Icon Image

    thanks for your quick response guys.
    I thought there might be a way with the QIcon states, I think it's just as easy to use the Pressed() and Released() slot. I've tried that and it works.

Similar Threads

  1. Adding Image to QPushButton
    By Seema Rao in forum Qt Programming
    Replies: 3
    Last Post: 18th November 2011, 10:06
  2. QPushButton with image - text alignment
    By vladeck in forum Newbie
    Replies: 3
    Last Post: 1st July 2009, 20:20
  3. QPushButton with image on it
    By msmihai in forum Newbie
    Replies: 1
    Last Post: 6th January 2009, 21:53
  4. Stretching Icon in QPushButton
    By dsandber in forum Qt Tools
    Replies: 1
    Last Post: 6th October 2007, 17:51
  5. Making Icon with more than one image
    By weepdoo in forum Qt Programming
    Replies: 9
    Last Post: 11th June 2007, 14:55

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.