Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
styles.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QStyleOption>
5#include <QStylePainter>
6#include <QWidget>
7
8class MyWidget : public QWidget
9{
10protected:
11 void paintEvent(QPaintEvent *event) override;
12 void paintEvent2(QPaintEvent *event);
13
14};
15
16//! [0] //! [1]
17void MyWidget::paintEvent(QPaintEvent * /* event */)
18//! [0]
19{
20 //! [2]
21 QPainter painter(this);
22 //! [2]
23
24 QStyleOptionFocusRect option;
25 option.initFrom(this);
26 option.backgroundColor = palette().color(QPalette::Window);
27
28 //! [3]
29 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
30 //! [3]
31}
32//! [1]
33
34void MyWidget::paintEvent2(QPaintEvent * /* event */)
35//! [4]
36{
37//! [4] //! [5] //! [6]
38 QStylePainter painter(this);
39 //! [5]
40
41 QStyleOptionFocusRect option;
42 option.initFrom(this);
43 option.backgroundColor = palette().color(QPalette::Window);
44
45 //! [7]
46 painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
47 //! [7]
48}
49//! [6]
50
51int main()
52{
53 return 0;
54}
void paintEvent2(QPaintEvent *event)
[1]
Definition styles.cpp:34
void paintEvent(QPaintEvent *event) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
int main()
[open]