PyQt 中的样式表伪状态语法
我有各种按钮在我的脚本中漫游,并且我正在加载外部 css 文件来处理我的软件中的大量小部件。我已经到了必须按类寻找按钮并尝试定义某些属性的地步。对按钮的通用调用,例如: QFrame:QPushButton #btnName { css: blah;正在工作,但是伪状态不起作用:特别是悬停和按下。这就是我正在尝试的:
--THIS WORKS
QFrame:QPushButton #btnName { css: blah; }
--THESE DO NOT
QFrame:QPushButton:hover #btnName { css: hoverstuff; }
QFrame:QPushButton:pressed #btnName { css: pressedstuff; }
工作表中有很多 css 样式;这可能是这些线“之上”的问题吗?我的伪状态语法是否错误?什么给!?提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您当前使用的语法在所有示例中都是错误的。
选择器
QFrame:QPushButton
将简单地忽略:QPushbutton
因为它不是有效的 伪状态。此外,ID 选择器之前的空格意味着该规则将应用于名为#btnName
的所有后代对象(这可能不是您想要的,但这就是第一个示例的原因)无论如何,有点作品)。我假设您真正想要的是将该规则应用于
objectName
为“btnName”的任何QPushButton
,它也是QFrame
的后代。代码>.在这种情况下,第一个规则应该是:
另外两个规则应该是:
请参阅 此处了解有关选择器类型的更多详细信息。
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 anobjectName
of "btnName", which is also a descendant of aQFrame
.In which case, the first rule should be:
and the other two rules should be:
See here for further details on Selector Types.