代码之家  ›  专栏  ›  技术社区  ›  pippo1980

Pyqt5-Python3-QPushButton默认StrongFocus颜色或选项卡选定颜色

  •  0
  • pippo1980  · 技术社区  · 5 年前

    我试图找到一种方法,使用Python3更改PyQt5中QPushButton的颜色。

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

    strong焦点颜色为默认颜色。找不到任何关于它的信息,我将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:按下不起作用。我刚开始,脚本上的按钮上没有连接或点击的功能。我正在使用Designer,我在QPushButton上得到的颜色与我在设计器预览中得到的颜色相同。

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

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

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

    有什么提示吗?

    0 回复  |  直到 5 年前
        1
  •  0
  •   pippo1980    4 年前

    musicmante回答了我的问题:

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