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
main.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 <QtGui>
5#include <QtWidgets>
6
7class MyPushButton : public QPushButton
8{
9public:
10 MyPushButton(QWidget *parent = nullptr);
11
12 void paintEvent(QPaintEvent *) override;
13};
14
15MyPushButton::MyPushButton(QWidget *parent)
17{
18}
19
20//! [0]
21void MyPushButton::paintEvent(QPaintEvent *)
22{
23 QStyleOptionButton option;
24 option.initFrom(this);
25 option.state = isDown() ? QStyle::State_Sunken : QStyle::State_Raised;
26 if (isDefault())
27 option.features |= QStyleOptionButton::DefaultButton;
28 option.text = text();
29 option.icon = icon();
30
31 QPainter painter(this);
32 style()->drawControl(QStyle::CE_PushButton, &option, &painter, this);
33}
34//! [0]
35
36
37
38class MyStyle : public QStyle
39{
40public:
41
42 void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
43 QPainter *painter, const QWidget *widget);
44};
45
46//! [4]
47void MyStyle::drawPrimitive(PrimitiveElement element,
48 const QStyleOption *option,
49 QPainter *painter,
50 const QWidget *widget)
51{
52 if (element == PE_FrameFocusRect) {
53 const QStyleOptionFocusRect *focusRectOption =
54 qstyleoption_cast<const QStyleOptionFocusRect *>(option);
55 if (focusRectOption) {
56 // ...
57 }
58 }
59 // ...
60}
61//! [4]
62
63int main(int argc, char *argv[])
64{
65 QApplication app(argc, argv);
66 MyPushButton button;
67 button.show();
68 return app.exec();
69}
MyPushButton(QWidget *parent=nullptr)
Definition main.cpp:15
void paintEvent(QPaintEvent *) override
[0]
Definition main.cpp:21
[0]
Definition main.cpp:39
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget)
[4]
Definition main.cpp:47
int main(int argc, char *argv[])
[ctor_close]