Qt 5.10 Book Examples
chapter18
LinearGradient
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
LinearGradientWidget
:
public
QWidget {
15
protected
:
16
virtual
void
paintEvent
(QPaintEvent*)
17
{
18
QPainter painter(
this
);
19
QLinearGradient gradient(0, 0, width(), height());
20
21
gradient.setColorAt(0, Qt::red);
22
gradient.setColorAt(0.5, Qt::green);
23
gradient.setColorAt(1, Qt::blue);
24
painter.setBrush(gradient);
25
painter.drawRect(rect());
26
}
27
28
public
:
29
LinearGradientWidget
(QWidget* pwgt = 0) : QWidget(pwgt)
30
{
31
}
32
};
33
34
// ----------------------------------------------------------------------
35
int
main
(
int
argc,
char
** argv)
36
{
37
QApplication app(argc, argv);
38
39
LinearGradientWidget
wgt;
40
41
wgt.show();
42
43
return
app.exec();
44
}
LinearGradientWidget::LinearGradientWidget
LinearGradientWidget(QWidget *pwgt=0)
Definition:
main.cpp:29
LinearGradientWidget
Definition:
main.cpp:14
main
int main(int argc, char **argv)
Definition:
main.cpp:15
LinearGradientWidget::paintEvent
virtual void paintEvent(QPaintEvent *)
Definition:
main.cpp:16
Generated by
1.8.14