Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Disabled QPushButton Not "Grayed Out"
Forum Updated to NodeBB v4.3 + New Features

Disabled QPushButton Not "Grayed Out"

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 23.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pfg23
    wrote on last edited by
    #1

    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.
    myButton->setStyleSheet(QString::fromUtf8("QPushButton[enabled=\"false\"]"
                                                        "{ 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);
    myButton->setPalette(btnPal);
    @
    No luck. What do I need to do to gray out the text of a QPushButton when it's disabled?

    Thanks,

    Phil

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pfg23
      wrote on last edited by
      #2

      Okay, then I tried this
      @
      myButton->setStyleSheet(QString::fromUtf8("QPushButton:disabled"
      "{ color: gray }"
      ));
      @
      And it worked!!!

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        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: http://bugreports.qt.nokia.com/browse/QTBUG-14601

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pfg23
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved