PDA

View Full Version : QPushButton when disabled becomes grayed out



alenn.masic
17th February 2013, 22:32
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?

wysota
17th February 2013, 23:19
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.

alenn.masic
18th February 2013, 09:05
Can you tell me how to interscept it's mouse and keyboard events

wysota
18th February 2013, 09:17
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.

Lykurg
18th February 2013, 10:07
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.)

wysota
18th February 2013, 10:12
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.

alenn.masic
18th February 2013, 16:22
I solved it using stylesheet. When I disable button I repeat this command: button->setStyleSheet("background-image: url(path_to_image);");

d_stranz
18th February 2013, 16:43
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.

alenn.masic
18th February 2013, 21:27
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)

d_stranz
19th February 2013, 02:25
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.