{"id":1890,"date":"2022-10-20T09:00:00","date_gmt":"2022-10-20T17:00:00","guid":{"rendered":"https:\/\/journal.copperspice.com\/?p=1890"},"modified":"2022-11-03T17:30:50","modified_gmt":"2022-11-04T01:30:50","slug":"source-code-gui-example-33","status":"publish","type":"post","link":"https:\/\/journal.copperspice.com\/?p=1890","title":{"rendered":"Source Code &nbsp;(Gui Example 33)"},"content":{"rendered":"\n<p>This example shows how to use low level drawing methods to create an ellipse, rounded rectangle, or a path shape and then set the pen to draw the border and the brush for the fill characteristics.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/\/ ellipse\nvoid DrawArea::paintEvent(QPaintEvent *)\n{\n   QRect rect(30, 60, 240, 180);\n\n   QPainter painter(this);\n   painter.setPen(pen);\n   painter.setBrush(brush);\n   painter.setRenderHint(QPainter::Antialiasing, true);\n\n   painter.save();\n   painter.translate(175, 10);\n   painter.drawEllipse(rect);\n   painter.restore();\n\n   painter.setRenderHint(QPainter::Antialiasing, false);\n   painter.setPen(palette().dark().color());\n   painter.setBrush(Qt::NoBrush);\n\n   painter.drawRect(QRect(0, 0, width() - 1, height() - 1));\n}\n\n\/\/ rounded rectangle\nvoid DrawArea::paintEvent(QPaintEvent *)\n{\n   QRect rect(30, 60, 240, 180);\n\n   QPainter painter(this);\n   painter.setPen(pen);\n   painter.setBrush(brush);\n   painter.setRenderHint(QPainter::Antialiasing, true);\n\n   painter.save();\n   painter.translate(175, 10);\n   painter.drawRoundedRect(rect, 25, 25, Qt::RelativeSize);\n   painter.restore();\n\n   painter.setRenderHint(QPainter::Antialiasing, false);\n   painter.setPen(palette().dark().color());\n   painter.setBrush(Qt::NoBrush);\n\n   painter.drawRect(QRect(0, 0, width() - 1, height() - 1));\n}\n\n\/\/ path\nvoid DrawArea::paintEvent(QPaintEvent *)\n{\n   QPainterPath path;\n   path.moveTo(60, 240);\n   path.lineTo(60, 90);\n   path.cubicTo(240, 0, 150, 150, 240, 240);\n\n   QPainter painter(this);\n   painter.setPen(pen);\n   painter.setBrush(brush);\n   painter.setRenderHint(QPainter::Antialiasing, true);\n\n   painter.save();\n   painter.translate(175, 10);\n   painter.drawPath(path);\n   painter.restore();\n\n   painter.setRenderHint(QPainter::Antialiasing, false);\n   painter.setPen(palette().dark().color());\n   painter.setBrush(Qt::NoBrush);\n\n   painter.drawRect(QRect(0, 0, width() - 1, height() - 1));\n}\n<\/pre><\/div>\n\n\n<p>Example 32 contained code to draw a polygon in a DrawArea. The source code in this example shows three variations of the DrawArea::paintEvent() method which will render an ellipse, rounded rectangle, or a path shape.  <\/p>\n\n\n\n<h3>Running the Example<\/h3>\n\n\n\n<p>To build and run this example use the source code for &#8220;example_32&#8221; and replace the DrawArea::paintEvent() with one of the implementations from this example.<\/p>\n\n\n\n<p><a href=\"https:\/\/download.copperspice.com\/journal\/example_33.zip\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/download.copperspice.com\/journal\/example_33.zip<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This example shows how to use low level drawing methods to create an ellipse, rounded rectangle, or a path shape and then set the pen to draw the border and the brush for the fill characteristics.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/posts\/1890"}],"collection":[{"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1890"}],"version-history":[{"count":10,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/posts\/1890\/revisions"}],"predecessor-version":[{"id":2035,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/posts\/1890\/revisions\/2035"}],"wp:attachment":[{"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}