主要繪制了圓弧, 帶弦的弧, 扇形, 繪制橢圓, 繪制五邊形和圖像
""" 繪制各種圖像 弧 圓形 橢圓 矩形(正方形) 多邊形 繪制圖像 """ import sys, math from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import * class DrawAll(QWidget): def __init__(self): super(DrawAll, self).__init__() self.resize(600, 900) self.setWindowTitle('繪制各種圖形') def paintEvent(self, event): qp = QPainter() qp.begin(self) qp.setPen(Qt.blue) #繪制弧 rect = QRect(0, 10, 100, 100) # alen: 1個alen等於1/16度 qp.drawArc(rect, 0, 50 * 16) #通過弧繪制園 qp.setPen(Qt.red) qp.drawArc(120, 10, 100, 100, 0, 360 * 16) #繪制帶弦的弧 qp.drawChord(10, 120, 100, 100, 12, 130 * 16) #繪制扇形 qp.drawPie(10, 240, 100, 100, 12, 130 * 16) #繪制橢圓 qp.drawEllipse(120, 120, 150, 100) #繪制5邊形 point1 = QPoint(140, 380) point2 = QPoint(270, 420) point3 = QPoint(290, 512) point4 = QPoint(290, 588) point5 = QPoint(200, 533) polygon = QPolygon([point1, point2, point3, point4, point5]) qp.drawPolygon(polygon) # 繪制圖像 image = QImage("D:\PyQt5_Study\picture\F6fhJr.jpg") rect = QRect(10, 600, image.width() / 3, image.height() / 3) qp.drawImage(rect, image) qp.end() if __name__ == "__main__": app = QApplication(sys.argv) main = DrawAll() main.show() sys.exit(app.exec_())