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. [Solved] Updating an object stylesheet to change color on "pressed" condition
Forum Updated to NodeBB v4.3 + New Features

[Solved] Updating an object stylesheet to change color on "pressed" condition

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 5.3k 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.
  • E Offline
    E Offline
    Endless
    wrote on last edited by
    #1

    In the constructor of my widget I have the following:
    @
    setStyleSheet("QPushButton:pressed { background-color: #808080 }");
    @

    Every button that's pushed turns colors. Depending on the state of each button, I change their individual stylesheets to change the normal background. I do something like:
    @
    button1->setStyleSheet("background: qradialgradient(cx: 0, cy: 0, radius: 0.8, fx: 0.5, fy: 0.5, stop: 0 #F0FFC0, stop: 1 #00FF50)";
    @

    The normal background changes fine, but after the first press event, it doesn't change background colors while it's being pressed. I tried all the combinations I could think of in the object setStyleSheet, but I never found one that worked. A lot of them caused a "Could not parse stylesheet of widget xxxx" error. How do I change the pressed state when setting an object stylesheet?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You mean something like this?
      @#include <QApplication>
      #include <QPushButton>

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);

      QPushButton pb("Button");
      pb.setStyleSheet("QPushButton { background-color: red; }"
                       "QPushButton:pressed { background-color: blue; }");
      pb.show();
      
      return a.exec(&#41;;
      

      }
      @

      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