PDA

View Full Version : QPushButton, different stylesheets for focus/pressed/released combinations.



anr78
5th January 2011, 19:14
I'm trying to accomplish some QPushButton-stylechanges, and need some help.

My aim is the following behaviour

Button Idle: White text on grey background
Button Pressed: White text on blue background
Button Idle+Focused: White text on grey background, border around it.
Button Pressed+Focused: White text on blue background, border around it.

I know how to create the mentioned looks using style sheets, but I'm not sure how to make it all come together.

As a test I did the following in a test application:
QPushButton { background-color: grey; }
QPushButton:focus:pressed { background-color: black; }
QPushButton:focus { background-color: green; }

That worked quite well, except that my button had focus by default, without me really understanding why. Could I reach my goal doing something similar?

How do I press/release a button and focus/unfocus it in my code? I tried calling click() without seeing any difference, but that might have been because of errors in my stylesheet I guess.

boudie
5th January 2011, 21:42
Make sure you have at least two buttons on your form when testing this.
Otherwise you won't see any difference between a button having the focus and one not having it.

zgulser
5th January 2011, 22:01
hi mate,

As far as I understand, you are suffering to have a button which probably on another widget of yours. If the problem is only appearing focused at first, all you need to do is unfocusing. boudie's suggestion is simple and clear I guess.

anr78
7th January 2011, 11:36
Thanks. A little more style-sheet-education on my part and it works.

Thomas_Lerman
16th September 2011, 02:10
I also tried the following:
QPushButton{ background-color: blue; }
QPushButton:disabled{ background-color: yellow; }
QPushButton:pressed{ background-color: orange; }
QPushButton:focus:pressed{ background-color: black; }
QPushButton:focus{ background-color: green; }
QPushButton:hover{ background-color: red; }
QPushButton:checked{ background-color: pink; }

I see the blue, red, green, pink, and black mostly as expected. I do not have a disabled button, but would expect that to work. What I am trying to figure out is when the button is checked (has the focus or does not have the focus), how do I NOT have the checker board background?