35. PyQt6 颜色
2023-10-17 python 731
import sys from PyQt6.QtWidgets import QApplication, QWidget from PyQt6.QtGui import QGuiApplication, QPainter, QColor class App(QWidget): def __init__(self): super().__init__() self.text = None self.setMinimumSize(50, 50) self.initUI() def initUI(self): self.setWindowTitle("PyQt6 颜色") self.setGeometry(100, 100, 400, 300) self.center() def paintEvent(self, event): qp = QPainter() qp.begin(self) self.drawRectangles(qp) qp.end() def drawRectangles(self, qp): col = QColor(0, 0, 0) col.setNamedColor("#d4d4d4") qp.setPen(col) qp.setBrush(QColor(200, 0, 0)) qp.drawRect(10, 15, 90, 60) qp.setBrush(QColor(255, 80, 0, 160)) qp.drawRect(130, 15, 90, 60) qp.setBrush(QColor(25, 0, 90, 200)) qp.drawRect(250, 15, 90, 60) def center(self): qr = self.frameGeometry() cp = QGuiApplication.primaryScreen().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) if __name__ == "__main__": app = QApplication(sys.argv) cls_app = App() cls_app.show() sys.exit(app.exec())
很赞哦! (0)
相关文章
文章评论
-
-
-
0条评论