class myMainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
#.......
self.pen = QPen(Qt.black, 2, Qt.SolidLine)
self.penColorFrame = QFrame()
self.penColorFrame.setAutoFillBackground(True)
self.penColorFrame.setPalette(QPalette(Qt.black))
self.penColorPushButton = QPushButton("change")
self.penColorPushButton.clicked.connect(self.penColorChange)#信号
#.......省略布局等各种东西
def penColorChange(self):#槽函数
color = QColorDialog.getColor(Qt.blue)#参数Qt.blue:调色盘选取颜色默认停在蓝色
self.penColorFrame.setPalette(QPalette(color))#设置控件背景颜色
self.pen.setColor(color)#设置笔颜色
QColor:
color = QColor(250,250,200)#RGB