{"id":8360,"date":"2019-10-29T23:29:51","date_gmt":"2019-10-29T14:29:51","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=8360"},"modified":"2020-05-28T10:04:37","modified_gmt":"2020-05-28T01:04:37","slug":"pyqt5-%eb%8b%a4%ec%96%91%ed%95%9c-%ea%b7%b8%eb%9e%98%ed%94%bd%ec%9d%84-%ed%91%9c%ed%98%84%ed%95%a0-%ec%88%98-%ec%9e%88%eb%8a%94-qpainter","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=8360","title":{"rendered":"[PyQt5] QPainter\ub97c \uc774\uc6a9\ud55c \ub2e4\uc591\ud55c \uadf8\ub798\ud53d"},"content":{"rendered":"<p>\uc704\uc82f\uc740 \uc790\uc2e0\uc744 \ub2e4\uc2dc \uadf8\ub9b4\ub54c paintEvent \ud568\uc218\ub97c \ud638\ucd9c\ud569\ub2c8\ub2e4. \uc989, \uc704\uc82f\uc5d0 \ubb34\uc5b8\uac00\ub97c \uadf8\ub9ac\uae30\uc5d0 \uac00\uc7a5 \uc801\ub2f9\ud55c \uc2dc\uc810\uc740 paintEvent\uc785\ub2c8\ub2e4. \ub610\ud55c \uc5ec\uae30\uc5d0 \uadf8\ub798\ud53d \uc694\uc18c\ub97c \uadf8\ub9ac\uae30 \uc704\ud574\uc11c QPainter\ub77c\ub294 API\ub97c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc774 \ub450\uac00\uc9c0\ub97c \uc870\ud569\ud558\uc5ec \uc704\uc82f\uc744 \uc0c1\uc18d\ubc1b\ub294 \uc708\ub3c4\uc6b0\ub97c \ud654\uba74\uc5d0 \ud45c\uc2dc\ud558\uace0 \uc774 \uc708\ub3c4\uc6b0\uc5d0 \uc6d0\ud558\ub294 \uadf8\ub798\ud53d \uc694\uc18c\ub97c \uadf8\ub9ac\ub294 \uc608\ub97c \uc0b4\ud3b4\ubcf4\uaca0\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\uba3c\uc800 \uc704\uc82f\uc744 \uc0c1\uc18d\ubc1b\ub294 MyWindow\ub77c\ub294 \ud074\ub798\uc2a4\ub97c \ud558\ub098 \uc815\uc758\ud558\ub294\ub370, \uc774 \ud074\ub798\uc2a4\uc5d0\ub294 \uc55e\uc11c \uc5b8\uae09\ud55c paintEvent \ud568\uc218\ub97c \uc7ac\uc815\uc758\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport sys, random\r\nfrom PyQt5.QtWidgets import QWidget, QApplication\r\nfrom PyQt5.QtGui import QPainter, QColor, QFont, QPen, QBrush, QPainterPath\r\nfrom PyQt5.QtCore import Qt\r\n\r\nclass MyWindow(QWidget):\r\n    def __init__(self):\r\n        super().__init__()\r\n        self.initUI()\r\n        \r\n    def initUI(self):      \r\n        self.setGeometry(300, 300, 400, 400)\r\n        self.setWindowTitle('QPainter\ub97c \uc774\uc6a9\ud55c \uadf8\ub798\ud53d\uc2a4')\r\n        self.show()\r\n\r\n    def paintEvent(self, event):\r\n        qp = QPainter()\r\n        qp.begin(self)\r\n\r\n        # \uadf8\ub9ac\uae30 \ud568\uc218\uc758 \ud638\ucd9c \ubd80\ubd84\r\n\r\n        qp.end()\r\n        \r\nif __name__ == '__main__':\r\n    app = QApplication(sys.argv)\r\n    ex = MyWindow()\r\n    sys.exit(app.exec_())\r\n<\/pre>\n<p>\uc704\uc758 \ucf54\ub4dc\uc5d0\uc11c 20\ubc88\uc9f8 \uc904\uc5d0 \uadf8\ub9ac\uae30 \ud568\uc218\ub97c \ud638\ucd9c\ud568\uc73c\ub85c\uc368 \uadf8 \uacb0\uacfc\ub97c \uc0b4\ud3b4\ubcfc \uc218 \uc788\ub294\ub370\uc694. \uadf8\ub9ac\uae30 \ud568\uc218\ub294 MyWindow \ud074\ub798\uc2a4\uc758 \ub9f4\ubc84 \ud568\uc218\ub85c\uc368 \uc815\uc758\ud569\ub2c8\ub2e4. \uba3c\uc800 \ud14d\uc2a4\ud2b8\ub97c \uadf8\ub9ac\ub294 \ud568\uc218\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\n    def drawText(self, event, qp):\r\n        qp.setPen(QColor(0, 0, 0))\r\n        qp.setFont(QFont('\ub098\ub214\uba85\uc870', 35))\r\n        qp.drawText(event.rect(), Qt.AlignCenter, '\uc2a4\uc0b0\ud55c \ub2a6\uac00\uc744\\n\uc544\ub2c8.. \ucd08\uaca8\uc6b8\uc778\uac00?')\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/10\/QPainter1.png\" alt=\"\" width=\"1024\" height=\"1068\" class=\"aligncenter size-full wp-image-8366\" \/><\/p>\n<p>\ub2e4\uc74c\uc740 \ud654\uba74\uc5d0 \ud3ec\uc778\ud2b8\ub97c \ucc0d\ub294 \ud568\uc218\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\n    def drawPoints(self, event, qp):\r\n        pen = QPen(Qt.gray, 3)\r\n        qp.setPen(pen)\r\n\r\n        size = self.size()\r\n        \r\n        for i in range(700):\r\n            x = random.randint(1, size.width()-1)\r\n            y = random.randint(1, size.height()-1)\r\n            qp.drawPoint(x, y)  \r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/10\/QPainter2.png\" alt=\"\" width=\"1024\" height=\"1068\" class=\"aligncenter size-full wp-image-8367\" \/><\/p>\n<p>\ub2e4\uc74c\uc740 \uc0ac\uac01\ud615\uc744 \uadf8\ub9ac\ub294 \ud568\uc218\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\n    def drawRectangles(self, qp):\r\n        col = QColor(0, 0, 0)\r\n        col.setNamedColor('#d4d4d4')\r\n        qp.setPen(col)\r\n\r\n        qp.setBrush(QColor(200, 0, 0))\r\n        qp.drawRect(50, 50, 100, 100)\r\n\r\n        qp.setBrush(QColor(255, 80, 0, 160))\r\n        qp.drawRect(150, 150, 100, 100)\r\n\r\n        qp.setBrush(QColor(25, 0, 90, 200))\r\n        qp.drawRect(250, 250, 100, 100)\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/10\/QPainter3.png\" alt=\"\" width=\"1024\" height=\"1068\" class=\"aligncenter size-full wp-image-8368\" \/><\/p>\n<p>\ub2e4\uc74c\uc740 \uc120\uc744 \uadf8\ub9ac\ub294 \ud568\uc218\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\n    def drawLines(self, qp):\r\n        pen = QPen(Qt.black, 3, Qt.SolidLine)\r\n\r\n        qp.setPen(pen)\r\n        qp.drawLine(50, 50, 350, 50)\r\n\r\n        pen.setStyle(Qt.DashLine)\r\n        qp.setPen(pen)\r\n        qp.drawLine(50, 110, 350, 110)\r\n\r\n        pen.setStyle(Qt.DashDotLine)\r\n        qp.setPen(pen)\r\n        qp.drawLine(50, 170, 350, 170)\r\n\r\n        pen.setStyle(Qt.DotLine)\r\n        qp.setPen(pen)\r\n        qp.drawLine(50, 230, 350, 230)\r\n\r\n        pen.setStyle(Qt.DashDotDotLine)\r\n        qp.setPen(pen)\r\n        qp.drawLine(50, 290, 350, 290)\r\n\r\n        pen.setStyle(Qt.CustomDashLine)\r\n        pen.setDashPattern([1, 4, 5, 4])\r\n        qp.setPen(pen)\r\n        qp.drawLine(50, 350, 350, 350)\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/10\/QPainter4.png\" alt=\"\" width=\"1024\" height=\"1068\" class=\"aligncenter size-full wp-image-8369\" \/><\/p>\n<p>\ub2e4\uc74c\uc740 \ub2e4\uc591\ud55c \ucc44\uc6c0 \uc2a4\ud0c0\uc77c\ub85c \uc0ac\uac01\ud615\uc744 \uadf8\ub9ac\ub294 \ud568\uc218\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\n    def drawBrushes(self, qp):\r\n        brush = QBrush(Qt.SolidPattern)\r\n        qp.setBrush(brush)\r\n        qp.drawRect(20, 20, 110, 110)\r\n\r\n        brush.setStyle(Qt.Dense1Pattern)\r\n        qp.setBrush(brush)\r\n        qp.drawRect(145, 20, 110, 110)\r\n\r\n        brush.setStyle(Qt.Dense2Pattern)\r\n        qp.setBrush(brush)\r\n        qp.drawRect(270, 20, 110, 110)\r\n\r\n        brush.setStyle(Qt.DiagCrossPattern)\r\n        qp.setBrush(brush)\r\n        qp.drawRect(20, 145, 110, 110)\r\n\r\n        brush.setStyle(Qt.Dense5Pattern)\r\n        qp.setBrush(brush)\r\n        qp.drawRect(145, 145, 110, 110)\r\n\r\n        brush.setStyle(Qt.Dense6Pattern)\r\n        qp.setBrush(brush)\r\n        qp.drawRect(270, 145, 110, 110)\r\n\r\n        brush.setStyle(Qt.HorPattern)\r\n        qp.setBrush(brush)\r\n        qp.drawRect(20, 270, 110, 110)\r\n\r\n        brush.setStyle(Qt.VerPattern)\r\n        qp.setBrush(brush)\r\n        qp.drawRect(145, 270, 110, 110)\r\n\r\n        brush.setStyle(Qt.BDiagPattern)\r\n        qp.setBrush(brush)\r\n        qp.drawRect(270, 270, 110, 110)\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/10\/QPainter5.png\" alt=\"\" width=\"1024\" height=\"1068\" class=\"aligncenter size-full wp-image-8370\" \/><\/p>\n<p>\ub2e4\uc74c\uc740 \ubca0\uc774\uc9c0 \uace1\uc120\uc744 \uadf8\ub9ac\ub294 \ud568\uc218\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\n    def drawBezierCurve(self, qp):\r\n        pen = QPen(Qt.black, 7)\r\n        qp.setPen(pen)\r\n\r\n        path = QPainterPath()\r\n        path.moveTo(50, 50)\r\n        path.cubicTo(200, 50, 50, 350, 350, 350)\r\n        \r\n        qp.drawPath(path)\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/10\/QPainter6.png\" alt=\"\" width=\"1024\" height=\"1068\" class=\"aligncenter size-full wp-image-8371\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc704\uc82f\uc740 \uc790\uc2e0\uc744 \ub2e4\uc2dc \uadf8\ub9b4\ub54c paintEvent \ud568\uc218\ub97c \ud638\ucd9c\ud569\ub2c8\ub2e4. \uc989, \uc704\uc82f\uc5d0 \ubb34\uc5b8\uac00\ub97c \uadf8\ub9ac\uae30\uc5d0 \uac00\uc7a5 \uc801\ub2f9\ud55c \uc2dc\uc810\uc740 paintEvent\uc785\ub2c8\ub2e4. \ub610\ud55c \uc5ec\uae30\uc5d0 \uadf8\ub798\ud53d \uc694\uc18c\ub97c \uadf8\ub9ac\uae30 \uc704\ud574\uc11c QPainter\ub77c\ub294 API\ub97c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc774 \ub450\uac00\uc9c0\ub97c \uc870\ud569\ud558\uc5ec \uc704\uc82f\uc744 \uc0c1\uc18d\ubc1b\ub294 \uc708\ub3c4\uc6b0\ub97c \ud654\uba74\uc5d0 \ud45c\uc2dc\ud558\uace0 \uc774 \uc708\ub3c4\uc6b0\uc5d0 \uc6d0\ud558\ub294 \uadf8\ub798\ud53d \uc694\uc18c\ub97c \uadf8\ub9ac\ub294 \uc608\ub97c \uc0b4\ud3b4\ubcf4\uaca0\uc2b5\ub2c8\ub2e4. \uba3c\uc800 \uc704\uc82f\uc744 \uc0c1\uc18d\ubc1b\ub294 MyWindow\ub77c\ub294 \ud074\ub798\uc2a4\ub97c \ud558\ub098 \uc815\uc758\ud558\ub294\ub370, \uc774 \ud074\ub798\uc2a4\uc5d0\ub294 \uc55e\uc11c \uc5b8\uae09\ud55c paintEvent \ud568\uc218\ub97c &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=8360\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;[PyQt5] QPainter\ub97c \uc774\uc6a9\ud55c \ub2e4\uc591\ud55c \uadf8\ub798\ud53d&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[131],"tags":[],"class_list":["post-8360","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8360"}],"version-history":[{"count":5,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8360\/revisions"}],"predecessor-version":[{"id":9362,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8360\/revisions\/9362"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8360"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}