Important: Please read the Qt Code of Conduct -

Disabled QPushButton Not "Grayed Out"

  • Hello,

    Simple need. In Qt for Symbian, when I call setEnabled(false) on my QPushButton, I expected the button text to automatically turn gray. It does not. I've tried the following but they don't work:
    QPushButton* myButton = new QPushButton(itsParentWidget);

    // 1. This just makes the button text gray, regardless of its enabledness.
                                                        "{ color: gray }"
                                                        "QPushButton"       // tried [enabled=\"true\"] too: nyet.
                                                        "{ color: black }"

    then I tried this...
    // 2. This just makes the button text black, and keeps it that way
    QPalette btnPal = myButton->palette();
    btnPal.setColor(QPalette::Disabled, QPalette::WindowText, Qt::lightGray);
    btnPal.setColor(QPalette::Active, QPalette::WindowText, Qt::black);
    No luck. What do I need to do to gray out the text of a QPushButton when it's disabled?



  • Okay, then I tried this
    "{ color: gray }"
    And it worked!!!

  • I would have expected this to work automatically, but that depends on the style you use. However, the fact that the property selector does not work for you, is a limitation caused by the fact that property changes do not trigger style-sheet re-evaluations. I filed a bug on that here:

  • Thanks for following up. This is an area in Qt where the "convention over configuration" paradigm is appropriate.

    You say you expected this to work automatically. Might it not have worked because the parent widget has a style sheet defined? It does in my case, although none of the QButtton properties or the default and active states are set in it.

Log in to reply