【发布时间】:2017-01-30 17:38:44
【问题描述】:
我目前正在尝试在 Qt 中自定义我的 QPushButton(实际上是 PyQt)。所以我设置了 StyleSheet 来做。
但问题是我需要将这个按钮设置为默认,通过 setDefault 为 True。
如果我这样做了,我会流口水……我怎样才能摆脱它?
这是一个例子:
button = QPushButton('login')
button.setDefault(True)
button.setObjectName('login')
button.setStyleSheet(
"""
QPushButton#login {
background-color: #4caf50;
color: white;
border: none;
}
QPushButton:pressed#login {
background-color: #59b75c;
}
"""
)
按钮显示为绿色,但文本不是全白...我尝试在 QPushButton:default 上设置 StyleSheet 但它根本没有改变任何东西
【问题讨论】:
-
我认为您的代码中缺少
button.setObjectName("login")。按钮构造函数的参数是显示文本。 -
另外,
QPushButton#login比QPushButton:default有先例。您需要使用QPushButton#login:default覆盖它。