summaryrefslogtreecommitdiffstats
path: root/src/widgets/doc/snippets/styles/styles.cpp
blob: 06fa19a89c57a81eda5d1706fc5a41d52f0fb1bd (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include <QStyleOption>
#include <QStylePainter>
#include <QWidget>

class MyWidget : public QWidget
{
protected:
    void paintEvent(QPaintEvent *event) override;
    void paintEvent2(QPaintEvent *event);

};

//! [0] //! [1]
void MyWidget::paintEvent(QPaintEvent * /* event */)
//! [0]
{
//! [2]
    QPainter painter(this);
//! [2]

    QStyleOptionFocusRect option;
    option.initFrom(this);
    option.backgroundColor = palette().color(QPalette::Background);

//! [3]
    style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
//! [3]
}
//! [1]

void MyWidget::paintEvent2(QPaintEvent * /* event */)
//! [4]
{
//! [4] //! [5] //! [6]
    QStylePainter painter(this);
//! [5]

    QStyleOptionFocusRect option;
    option.initFrom(this);
    option.backgroundColor = palette().color(QPalette::Background);

//! [7]
    painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
//! [7]
}
//! [6]

int main()
{
    return 0;
}