PDA

View Full Version : QPushButton with two states and colours



hildebrand
3rd June 2013, 13:20
I need a pushbutton in GUI with two states. My requirements are as follows:-
1. It should have ON and OFF states. On clicking it should toggle between both.
2. When ON it should be in Red colour. When OFF it should be Green colour.
3. In either state a different job has to be done.
How can I implement this?

KaptainKarl
3rd June 2013, 14:25
Review the setCheckable() method of the QPushButton class.

Karl

hildebrand
5th June 2013, 03:46
I tried this approach with me changing the Stylesheet in the toggled slot but the look I get is not what I want. I am expecting the buttons to look the way they do in the picture below in both states:-
9100
However, second state looks like shown in top button here. It is embedded and colour is not coming properly like I expect in the button below. How do I get the correct red look as wanted?
9101

wysota
5th June 2013, 08:22
Subclass and reimplement paintEvent() to do your own painting.