Issue
I am creating a stylesheet .qss
file for the GUI. I am trying to add the QToolButton
method autoRaise
to the style sheet as:
btn_on = QToolButton()
btn_on.setStyleSheet("""
QToolButton:autoRaised{
color: rgb(0,0,0);
background-color: rgb(142,142,142);
}
""")
btn_on.setAutoRaise(True)
But it doesn't recognize the autoRaise
attribute. This is same as you define a disabled
attribute for the QPushButton
, which is working:
ss = QPushButton()
ss.setStyleSheet("""
QToolButton:autoRaised{
color: rgb(0,0,0);
background-color: rgb(142,142,142);
}
""")
ss.setDisabled(True)
How can I define the autoRaise
attribute inside the .qss
file?
Solution
The autoRaise
(without a final "D") is a Qt property.
The :syntax
is used for pseudo states, normally indicating a state of the widget or a generic property.
They are predefined and common to all widgets, even if some states are only supported by some widgets (like :read-only
for a text widget) and based on the CSS pseudo-classes; see the full list of supported pseudo states.
If you want to set the style based on a property, you must properly use the property selector syntax:
QToolButton[autoRaise="true"] {
color: rgb(0,0,0);
background-color: rgb(142,142,142);
}
Note that styles might override some painting or completely ignore the color in some situations. For instance, on Linux with the Oxygen and Breeze styles, the hovered style ignores the color and uses the default painting.
Also note that stylesheets are evalued only once, so if the property changes the change won't be reflected: you need to re-set the stylesheet again. This cannot be done automatically.
btn_on.setAutoRaise(False)
btn_on.setStyleSheet(btn_on.styleSheet())
If the stylesheet is set on a parent or the application and the target widget has no stylesheet set, you must re-set the stylesheet for that parent or the application.
Answered By - musicamante
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.