Oğuzhan Türk
Oğuzhan Türk

Reputation: 380

How to re-add pressed/clicked effect to QPushButton?

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?

Upvotes: 0

Views: 5236

Answers (3)

Oğuzhan Türk
Oğuzhan Türk

Reputation: 380

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

Upvotes: 1

thuga
thuga

Reputation: 12901

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.

Upvotes: 4

mbroadst
mbroadst

Reputation: 888

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);
}

Upvotes: 3

Related Questions