Python PyQt5按钮背景色不生效

Python PyQt5按钮背景色不生效,python,pyqt5,Python,Pyqt5,以下是按钮的代码: self.pushButton.setFont(font) self.pushButton.setStyleSheet("background-color: qlineargradient(spread:pad, x1:0.0568182, y1:0.126, x2:0.75, y2:0.227, stop:0.0738636 rgba(0, 255, 0, 255), stop:0.840909 rgba(0, 136, 0, 255));\n")

以下是按钮的代码:

    self.pushButton.setFont(font)
    self.pushButton.setStyleSheet("background-color: qlineargradient(spread:pad, x1:0.0568182, y1:0.126, x2:0.75, y2:0.227, stop:0.0738636 rgba(0, 255, 0, 255), stop:0.840909 rgba(0, 136, 0, 255));\n")
    self.pushButton.setFlat(True)
    self.pushButton.setObjectName("pushButton")
虽然我为这个按钮设置了背景渐变,但它不会生效

这是按钮:

以下是按下按钮的时间:

好的。问题解决了


问题是,我使用了背景色,但是背景:#fff成功了。

文档来源:警告:如果只在QPushButton上设置背景色,除非将border属性设置为某个值,否则背景可能不会显示。这是因为,默认情况下,QPushButton绘制的本机边框与背景色完全重叠。抱歉,它不起作用。我很好奇为什么会起作用。据我所知,没有任何文件表明要这样做。你为什么要尝试这个,它的文档在哪里?我也不知道。没有文件表明soI对此做了一些研究。很容易找到十几个其他人有同样问题的链接。Qt调色板、样式表和操作系统之间似乎存在一些奇怪的交互。如果有人真的明白了,他就不会说话。你的解决方案非常有趣,我没有看到其他人这样做。