PyQt 中的样式表伪状态语法

发布于 2025-01-03 14:37:59 字数 440 浏览 1 评论 0原文

我有各种按钮在我的脚本中漫游,并且我正在加载外部 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や三分注定 2025-01-10 14:37:59

您当前使用的语法在所有示例中都是错误的。

选择器 QFrame:QPushButton 将简单地忽略 :QPushbutton 因为它不是有效的 伪状态。此外,ID 选择器之前的空格意味着该规则将应用于名为 #btnName所有后代对象(这可能不是您想要的,但这就是第一个示例的原因)无论如何,有点作品)。

我假设您真正想要的是将该规则应用于 objectName 为“btnName”的任何 QPushButton,它也是 QFrame的后代。代码>.

在这种情况下,第一个规则应该是:

QFrame QPushButton#btnName { css: blah; }

另外两个规则应该是:

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

请参阅 此处了解有关选择器类型的更多详细信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文