[英]QPushbutton How to remove the color created by setDefault(True)
I'm currently try to custom my QPushButton in Qt (PyQt in fact).我目前正在尝试在 Qt(实际上是 PyQt)中自定义我的 QPushButton。 So I set StyleSheet to do it.
所以我设置了 StyleSheet 来做到这一点。
But the problem is that I need to set this button to Default by setDefault to True.但问题是我需要通过 setDefault 将这个按钮设置为 Default 为 True。
And if I do that, I've a sort of color drool over ... how can I get rid of it?如果我这样做,我会流口水……我怎么能摆脱它?
Here is an example:下面是一个例子:
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;
}
"""
)
Button appears green, but text is not fully white... I've try to set StyleSheet on QPushButton:default
But it does not change anything at all按钮显示为绿色,但文本不是完全白色...我尝试在
QPushButton:default
上设置 StyleSheet 但它根本没有改变任何东西
I can see you have a small error in your code.我可以看到您的代码中有一个小错误。 you gave us
你给了我们
QPushButton:pressed#login {
background-color: #59b75c;
}
but this does not work.但这不起作用。
The correct way to do it is正确的做法是
QPushButton#login:pressed {
background-color: #59b75c;
}
also, be sure that after the '#' you use the objectName of the pushButton and not the text of the button.另外,请确保在“#”之后使用按钮的 objectName 而不是按钮的文本。
Here is a link with some styleSheet examples这是一些样式表示例的链接
After long searches on the internet, I finally found how to do.在网上找了很久,终于找到方法了。 I've to set
outline
to none
to remove it.我必须将
outline
设置为none
以将其删除。
QPushButton#login {
background-color: #4caf50;
color: white;
outline: none;
}
Then slobbery color disappear.然后流口水的颜色消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.