Qt 5.10 Book Examples
main.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // main.cpp
3 // ======================================================================
4 // This file is a part of the book
5 // "Qt 5.10 Professional programming with C++"
6 // http://qt-book.com
7 // ======================================================================
8 // Copyright (c) 2017 by Max Schlee
9 // ======================================================================
10 
11 #include <QtWidgets>
12 
13 // ======================================================================
14 class PainterPathWidget : public QWidget {
15 protected:
16  virtual void paintEvent(QPaintEvent*)
17  {
18  QPainterPath path;
19  QPointF pt1(width(), height() / 2);
20  QPointF pt2(width() / 2, -height());
21  QPointF pt3(width() / 2, 2 * height());
22  QPointF pt4(0, height() / 2);
23  path.moveTo(pt1);
24  path.cubicTo(pt2, pt3, pt4);
25 
26  QRect rect(width() / 4, height() / 4, width() / 2, height() / 2);
27  path.addRect(rect);
28  path.addEllipse(rect);
29 
30  QPainter painter(this);
31  painter.setRenderHint(QPainter::Antialiasing, true);
32  painter.setPen(QPen(Qt::blue, 6));
33  painter.drawPath(path);
34  }
35 
36 public:
37  PainterPathWidget(QWidget* pwgt = 0) : QWidget(pwgt)
38  {
39  }
40 };
41 
42 // ----------------------------------------------------------------------
43 int main(int argc, char** argv)
44 {
45  QApplication app(argc, argv);
46 
48 
49  wgt.resize(200, 200);
50  wgt.show();
51 
52  return app.exec();
53 }
PainterPathWidget(QWidget *pwgt=0)
Definition: main.cpp:37
int main(int argc, char **argv)
Definition: main.cpp:15
virtual void paintEvent(QPaintEvent *)
Definition: main.cpp:16