Qt 5.10 Book Examples
chapter20
DrawText
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
DrawTextWidget
:
public
QWidget {
15
protected
:
16
virtual
void
paintEvent
(QPaintEvent*)
17
{
18
QPainter painter(
this
);
19
QRect r = rect();
20
painter.setFont(QFont(
"Times"
, 50, QFont::Normal));
21
painter.drawRect(r);
22
painter.drawText(r, Qt::AlignCenter | Qt::TextWordWrap,
"Draw Text"
);
23
}
24
25
public
:
26
DrawTextWidget
(QWidget* pwgt = 0) : QWidget(pwgt)
27
{
28
}
29
};
30
31
32
// ----------------------------------------------------------------------
33
int
main
(
int
argc,
char
** argv)
34
{
35
QApplication app(argc, argv);
36
37
DrawTextWidget
dtw;
38
39
dtw.resize(200, 150);
40
dtw.show();
41
42
return
app.exec();
43
}
DrawTextWidget
Definition:
main.cpp:14
DrawTextWidget::paintEvent
virtual void paintEvent(QPaintEvent *)
Definition:
main.cpp:16
main
int main(int argc, char **argv)
Definition:
main.cpp:15
DrawTextWidget::DrawTextWidget
DrawTextWidget(QWidget *pwgt=0)
Definition:
main.cpp:26
Generated by
1.8.14