【问题标题】:QPushbutton How to remove the color created by setDefault(True)QPushbutton 如何移除 setDefault(True) 创建的颜色
【发布时间】: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#loginQPushButton:default 有先例。您需要使用QPushButton#login:default 覆盖它。

标签: qt pyqt


【解决方案1】:

我可以看到您的代码中有一个小错误。你给了我们

QPushButton:pressed#login {
    background-color: #59b75c;
}

但这不起作用。

正确的做法是

QPushButton#login:pressed {
    background-color: #59b75c;
}

另外,请确保在“#”之后使用 pushButton 的 objectName 而不是按钮的文本。

这里是一些styleSheet examples的链接

【讨论】:

    【解决方案2】:

    在网上搜索了很久,终于找到了方法。我必须将 outline 设置为 none 才能删除它。

    QPushButton#login {
        background-color: #4caf50;
        color: white;
        outline: none;
    }
    

    然后流口水的颜色就消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-26
      • 2014-01-07
      • 1970-01-01
      • 2014-08-30
      • 2015-02-03
      • 1970-01-01
      相关资源
      最近更新 更多