【发布时间】:2019-03-09 06:44:18
【问题描述】:
我正在尝试使用 python Qt 更改边框的背景颜色,但只设置了边框。
这是代码:
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtCore import pyqtSlot
import math
import sys
class Frame(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 100, 1000, 500)
pal = QPalette()
self.setAutoFillBackground(True)
self.setPalette(pal)
button = QPushButton('Clear Knots')
button.clicked.connect(quit)
pal.setColor(QPalette.Button, QColor(255,0,0,255))
button.setPalette(pal)
button.setAutoFillBackground(True)
#button.setStyleSheet("background-color: red;")
Layout = QGridLayout()
Layout.addWidget(button, 2,0)
self.setLayout(Layout)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Frame()
sys.exit(app.exec_())
结果:
【问题讨论】:
-
不需要做
Palette的东西,只要做样式表,你已经做了,只是注释掉了,取消注释。 -
不起作用,没有它我什至没有得到红色轮廓
-
当我取消注释
setStyleSheet行时,它适用于PyQt4。 -
取消注释
setStyleSheet()也适用于 Python 3.6.5、Qt 5.9.3、PyQt5 5.9.2 -
哪个操作系统?
标签: python qt user-interface pyqt5