0

When I set a background color for a QPushButton at its stylesheet, it loses pressed/clicked effect. How can I fix this? How can I re-add this effect?

Oğuzhan Türk
  • 360
  • 2
  • 9
  • 21

3 Answers3

4

Stylesheets can have pseudo states. To style the pressed state of a push button, you can use something like this as your stylesheet:

QPushButton:pressed {
    background-color: red;
}

You can read more about the pseudo-states here.

Here is an example of customizing a QPushButton.

thuga
  • 12,601
  • 42
  • 52
2

You can use style sheets to customize the look and feel of a QPushButton. There is a great list of examples here showing off what you can do. Specifically, you'll be looking at the "pressed" state:

QPushButton:pressed {
    background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                      stop: 0 #dadbde, stop: 1 #f6f7fa);
}
mbroadst
  • 768
  • 6
  • 8
  • AVAST popups and blocks access to the qt-project.org site linked, saying that it's a phishing site. May want to check it to be sure. – Mike from PSG Dec 16 '19 at 18:09
1

I found the solution of my problem. I removed "border" declaration/definition at widget that contains these push buttons. Thus problem is solved.

Oğuzhan Türk
  • 360
  • 2
  • 9
  • 21