drawChord() 에 x, y, width, height, start-angle, span-angle의 순서로 숫자를 입력하여 현을 그리는데 사용합니다.
start-angle, span-angle에 각도를 숫자로 입력할 때 0 (0도) 부터 5760 (360도)까지의 숫자를 입력합니다.
예를 들어 30도를 나타내고 싶다면 30 * 16을 입력합니다.
54-1 예제: ex53
import sys from PyQt5.QtWidgets import (QApplication, QWidget) from PyQt5.QtGui import (QPainter, QPen, QColor, QBrush) from PyQt5.QtCore import Qt class MyApp(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 400, 300) self.setWindowTitle('drawChord') self.show() def paintEvent(self, e): qp = QPainter() qp.begin(self) self.draw_chord(qp) qp.end() def draw_chord(self, qp): qp.setPen(QPen(Qt.black, 3)) qp.drawChord(20, 20, 100, 100, 0 * 16, 30 * 16) qp.drawText(60, 100, '30°') qp.drawChord(150, 20, 100, 100, 0 * 16, 60 * 16) qp.drawText(190, 100, '60°') qp.drawChord(280, 20, 100, 100, 0 * 16, 90 * 16) qp.drawText(320, 100, '90°') qp.drawChord(20, 140, 100, 100, 0 * 16, 180 * 16) qp.drawText(60, 270, '180°') qp.drawChord(150, 140, 100, 100, 0 * 16, 270 * 16) qp.drawText(190, 270, '270°') qp.drawChord(280, 140, 100, 100, 0 * 16, 360 * 16) qp.drawText(320, 270, '360°') if __name__ == '__main__': app = QApplication(sys.argv) win = MyApp() sys.exit(app.exec_()) |
54-2 결과
54-3 예제2
import sys from PyQt5.QtWidgets import (QApplication, QWidget) from PyQt5.QtGui import (QPainter, QPen, QColor, QBrush) from PyQt5.QtCore import Qt class MyApp(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 400, 300) self.setWindowTitle('drawChord') self.show() def paintEvent(self, e): qp = QPainter() qp.begin(self) self.draw_chord(qp) qp.end() def draw_chord(self, qp): brush = QBrush(Qt.SolidPattern) qp.setBrush(brush) qp.drawChord(20, 10, 100, 100, 30 * 16, 120 * 16) qp.drawText(20, 90, 'Qt.SolidPattern') brush = QBrush(Qt.Dense1Pattern) qp.setBrush(brush) qp.drawChord(150, 10, 100, 100, 30 * 16, 120 * 16) qp.drawText(150, 90, 'Qt.Dense1Pattern') brush = QBrush(Qt.Dense2Pattern) qp.setBrush(brush) qp.drawChord(280, 10, 100, 100, 30 * 16, 120 * 16) qp.drawText(280, 90, 'Qt.Dense2Pattern') brush = QBrush(Qt.HorPattern) qp.setBrush(brush) qp.drawChord(20, 110, 100, 100, 0 * 16, 135 * 16) qp.drawText(20, 190, 'Qt.HorPattern') brush = QBrush(Qt.VerPattern) qp.setBrush(brush) qp.drawChord(150, 110, 100, 100, 0 * 16, 135 * 16) qp.drawText(150, 190, 'Qt.VerPattern') brush = QBrush(Qt.CrossPattern) qp.setBrush(brush) qp.drawChord(280, 110, 100, 100, 0 * 16, 135 * 16) qp.drawText(280, 190, 'Qt.CrossPattern') brush = QBrush(Qt.BDiagPattern) qp.setBrush(brush) qp.drawChord(20, 210, 100, 100, 45 * 16, 135 * 16) qp.drawText(20, 290, 'Qt.BDiagPattern') brush = QBrush(Qt.FDiagPattern) qp.setBrush(brush) qp.drawChord(150, 210, 100, 100, 45 * 16, 135 * 16) qp.drawText(150, 290, 'Qt.FDiagPattern') brush = QBrush(Qt.DiagCrossPattern) qp.setBrush(brush) qp.drawChord(280, 210, 100, 100, 45 * 16, 135 * 16) qp.drawText(270, 290, 'Qt.DiagCrossPattern') if __name__ == '__main__': app = QApplication(sys.argv) win = MyApp() sys.exit(app.exec_()) |
QBrush()와 setBrush()를 이용하면 채욱 패턴을 다양하게 설정할 수 있습니다.
54-4 결과
'프로그래밍 > PyQt5 GUI' 카테고리의 다른 글
56. 텍스트 그리고 (drawText) (0) | 2021.07.30 |
---|---|
55. 파이 그리기 (drawPie) (0) | 2021.07.30 |
53. 호 그리기 (drawArc) (0) | 2021.07.30 |
52. 타원 그리기 (drawEllipse) (0) | 2021.07.29 |
51. 다각형 그리기 (drawPolygon) (0) | 2021.07.29 |