I have various PushButtons roaming about my script, and I'm loading in an external css file to handle the mass of widgets in my software. I'm getting to the point where I'm having to hunt down buttons by class and trying to define certain properties. The generic call to a button, like: QFrame:QPushButton #btnName { css: blah; } is working, however the pseudo-states are not: specifically hover and pressed. Here's what i'm trying:

--THIS WORKS
QFrame:QPushButton #btnName { css: blah; }

--THESE DO NOT
QFrame:QPushButton:hover #btnName { css: hoverstuff; }
QFrame:QPushButton:pressed #btnName { css: pressedstuff; }

There are plenty of css stylings in the sheet; could it be a matter of what's 'above' these lines? Is my syntax wrong for the pseudo-states? What gives!? Thanks in advance.

有帮助吗?

解决方案

The current syntax you are using is wrong in all your examples.

The selector QFrame:QPushButton will simply ignore :QPushbutton because it is not a valid pseudo-state. Also, the space before the ID Selector means that the rule will apply to all descendant objects called #btnName (which is probably not what you intended, but is why the first example sort of works anyway).

I assume what you really wanted was for the rule to apply to any QPushButton with an objectName of "btnName", which is also a descendant of a QFrame.

In which case, the first rule should be:

QFrame QPushButton#btnName { css: blah; }

and the other two rules should be:

QFrame QPushButton#btnName:hover { css: hoverstuff; }
QFrame QPushButton#btnName:pressed { css: pressedstuff; }

See here for further details on Selector Types.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top