summaryrefslogtreecommitdiffstats
path: root/src/gui/doc/snippets/code/src_gui_painting_qregion.cpp
blob: 6401c29de565a6fdd9b0027554ea49dcda56411c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QPaintEvent>
#include <QPainter>

namespace src_gui_painting_qregion {
struct MyWidget : public QPaintDevice
{
    void paintEvent(QPaintEvent *);
};

//! [0]
void MyWidget::paintEvent(QPaintEvent *)
{
    QRegion r1(QRect(100, 100, 200, 80),    // r1: elliptic region
               QRegion::Ellipse);
    QRegion r2(QRect(100, 120, 90, 30));    // r2: rectangular region
    QRegion r3 = r1.intersected(r2);        // r3: intersection

    QPainter painter(this);
    painter.setClipRegion(r3);
    // ...                                  // paint clipped graphics
}
//! [0]

} // src_gui_painting_qregion