Pyqt5 Python3 QPushButton 默认 StrongFocus 颜色或 tab 选中颜色

Pyqt5 Python3 QPushButton default StrongFocus color or tab selected color

我正在尝试找出一种使用 Python3.

更改 PyQt5 中 QPushButton 颜色的方法

我可以设置背景颜色和悬停颜色,但程序会保留焦点颜色或

strongfocus 颜色作为默认颜色。找不到任何相关信息,我在我的

中加载了我的 qss 文件 StyleSheet

main.py.

喜欢

QPushButton{
    background-color: #9de650;       #works fine
}


QPushButton:hover{
    background-color: green;         #works fine
}

QPushButton:focus {
    background-color: red;           #doesnt work if the focus color is the color of the button you can
    }                                # change using tab to navigate among a list of buttons

QPushButton:strong:focus {           #doenst work
    background-color: red; 
    }

QPushButton:pressed {                #doesnt work get the tab color
    background-color: green; 
    }

我不明白为什么 QPushButton:pressed 不起作用。我刚开始,我的脚本按钮上没有连接或点击功能。我正在使用 Designer,我在 QPushButton 上获得的颜色与我在设计器预览中获得的颜色相同。

如果我将 qss 代码直接保存到设计器中的 ui 文件中,同样的行为。

在我的按钮列表之间切换时,我可以看到它们在很短的时间内呈现红色

在变成蓝色之前,红色是我重点选择的颜色。

有什么提示吗?

musicmante 回答了我的问题:

和我想的一样。如果小部件的 css 定义不完整,Breeze 会覆盖一些颜色和行为;奇怪的是你说 button:pressed 不起作用,但它在我的测试中起作用。无论如何,Fusion 是通常可以更好地处理样式表的样式,如果使用它不是问题,您可以使用 app.setStyle(QtWidgets.QStyleFactory.create('Fusion') 设置应用程序样式).