from PyQt5.QtGui import QPainter, QPolygon, QColor from PyQt5.QtWidgets import QWidget, QApplication import sys class Example(QWidget): def __init__(self): super().__init__() self.setGeometry(300, 300, 350, 200) def paintEvent(self, event): qp = QPainter(self) qp.setPen(QColor(0, 0, 0)) qp.setBrush(QColor(255, 0, 0)) points = QPolygon([QPoint(50, 50), QPoint(150, 50), QPoint(100, 150)]) qp.drawPolygon(points) if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() ex.show() sys.exit(app.exec_())
from PyQt5.QtGui import QPainter, QPolygon from PyQt5.QtWidgets import QWidget, QApplication import sys class Example(QWidget): def __init__(self): super().__init__() self.setGeometry(300, 300, 350, 200) def paintEvent(self, event): qp = QPainter(self) qp.setPen(Qt.black) qp.setBrush(Qt.blue) polygon1 = QPolygon([QPoint(50, 50), QPoint(150, 50), QPoint(100, 150)]) polygon2 = QPolygon([QPoint(200, 50), QPoint(300, 50), QPoint(250, 150)]) polygon3 = QPolygon([QPoint(100, 100), QPoint(200, 100), QPoint(150, 200)]) qp.drawPolygon(polygon1) qp.drawPolygon(polygon2) qp.drawPolygon(polygon3) if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() ex.show() sys.exit(app.exec_())In the above examples, QPolygon is used to create a list of points, and QPainter is used to draw polygons on a widget or a QPainter device. The library used in these examples is PyQt5.QtGui.