Qt 5.10 Book Examples
chapter20
GradientText
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
QLinearGradient gradient(0, 0, 500, 0);
19
gradient.setColorAt(0, Qt::red);
20
gradient.setColorAt(0.5, Qt::green);
21
gradient.setColorAt(1, Qt::blue);
22
23
QPainter painter(
this
);
24
painter.setPen(QPen(gradient, 0));
25
painter.setFont(QFont(
"Times"
, 50, QFont::Normal));
26
painter.drawText(60, 60,
"Gradient Text"
);
27
}
28
29
public
:
30
DrawTextWidget
(QWidget* pwgt = 0) : QWidget(pwgt)
31
{
32
}
33
};
34
35
36
// ----------------------------------------------------------------------
37
int
main
(
int
argc,
char
** argv)
38
{
39
QApplication app(argc, argv);
40
41
DrawTextWidget
dtw;
42
43
dtw.resize(500, 80);
44
dtw.show();
45
46
return
app.exec();
47
}
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:30
Generated by
1.8.14