Styled PushButton in checked state
-
wrote on 20 Jun 2015, 18:04 last edited by Andy314
Hello !
I want a pushbutton with a green background in checked state and tried this style for the button:
checked {background-color: green ; border: none;}
This style has no effect!What I am doing wrong?
PS: I use Windows 8.1
-
Hi,
QPushButton:checked {background-color: green; border: none;}
will do what you want
-
wrote on 21 Jun 2015, 15:25 last edited by
Works!
Thank you, I thought the property of the QPushButton has the local context QPushButton. -
You were missing the
:
beforechecked
so
":checked {background-color: green ; border: none;}"
will also work -
You were missing the
:
beforechecked
so
":checked {background-color: green ; border: none;}"
will also workwrote on 22 Jun 2015, 16:27 last edited byHello @SGaist !
:checked {background-color: lightgreen; border: 1px solid;}
QPushButton {background-color: red; border: 1px solid; padding: 6px}
works.but how I can avoid the second type name ?
(I need this style for different widgedts) -
AFAIK, you can't, however you can still re-use it by using something like:
QString styleSheet("%1:checked {background-color: lightgreen; border: 1px solid;} " "%1 {background-color: red; border: 1px solid; padding: 6px}"); myWidget->setStyleSheet(styleSheet.arg(myWidget->metaObject()->className()));
1/6