Results 1 to 10 of 10

Thread: QPushButton when disabled becomes grayed out

  1. #1
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPushButton when disabled becomes grayed out

    Hello

    When I disable QPushButton it becomes grayed out by default, how can I leave it as it is even if it is disabled. I have icon on QPushButton and when I disable button I want icon to stay as it was before. How can I solve this?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPushButton when disabled becomes grayed out

    Either reimplement the button's paintEvent() and change the options that get passed to QStyle::drawComplexControl() (or whatever gets called there) or don't make the button disabled but just disable triggering it by intercepting its mouse and key events.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPushButton when disabled becomes grayed out

    Can you tell me how to interscept it's mouse and keyboard events

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPushButton when disabled becomes grayed out

    Quote Originally Posted by alenn.masic View Post
    Can you tell me how to interscept it's mouse and keyboard events
    Either subclass and reimplement appropriate event handlers or install an event filter on an existing object.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QPushButton when disabled becomes grayed out

    Shouldn't it be possible just to change the palette? I mean, replace all colors of QPalette::Disabled with those of QPalette::Active. (Not tried.)

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPushButton when disabled becomes grayed out

    Quote Originally Posted by Lykurg View Post
    Shouldn't it be possible just to change the palette? I mean, replace all colors of QPalette::Disabled with those of QPalette::Active. (Not tried.)
    No, the icon will still be greyed out. But I think it might be possible to explicitly set the regular icon pixmap as the disabled icon pixmap using QIcon::addPixmap() and passing Disabled as the mode.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPushButton when disabled becomes grayed out

    I solved it using stylesheet. When I disable button I repeat this command: button->setStyleSheet("background-image: url(path_to_image);");

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPushButton when disabled becomes grayed out

    Aside from the mechanics of how you get this to work, why would you want to show a button as enabled when it isn't? There's a reason why there are various states for UI controls (enabled, disabled, selected, etc.) - it is to give users a visual clue about what they can (or can't) do at a given point, or what will happen by default (the selected button will be "clicked" if you press Enter on a dialog).

    Why would you want to implement a GUI that is deliberately confusing to users? I can see someone repeatedly clicking on this button, and getting angrier each time because nothing happens.

  9. #9
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPushButton when disabled becomes grayed out

    Because I'm using my own icon to show that button is disabled. I only need to put big X on top of my button and that will indicate it is disabled (I'm making a game)

  10. The following user says thank you to alenn.masic for this useful post:

    d_stranz (19th February 2013)

  11. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPushButton when disabled becomes grayed out

    OK, that makes sense. As long as you show the user somehow that "You can't press this button now", then that is consistent with what the user expects.

Similar Threads

  1. Replies: 0
    Last Post: 21st February 2012, 03:45
  2. Scrollbar always grayed out
    By Gargolissimus in forum Newbie
    Replies: 5
    Last Post: 6th July 2009, 21:22
  3. QPushbutton with background image when disabled
    By soumyadeep_pan in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2009, 16:50
  4. QPushButton grayed out
    By stefan1981 in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2009, 15:27

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.