Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
7
class
MyPushButton
:
public
QPushButton
8
{
9
public
:
10
MyPushButton
(QWidget *parent =
nullptr
);
11
12
void
paintEvent
(QPaintEvent *)
override
;
13
};
14
15
MyPushButton
::
MyPushButton
(QWidget *parent)
16
:
QPushButton
(
parent
)
17
{
18
}
19
20
//! [0]
21
void
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
38
class
MyStyle
:
public
QStyle
39
{
40
public
:
41
42
void
drawPrimitive
(PrimitiveElement element,
const
QStyleOption *option,
43
QPainter *painter,
const
QWidget *widget);
44
};
45
46
//! [4]
47
void
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
63
int
main
(
int
argc,
char
*argv[])
64
{
65
QApplication app(argc, argv);
66
MyPushButton
button;
67
button.show();
68
return
app.exec();
69
}
MyPushButton
[26]
Definition
doc_src_stylesheet.cpp:43
MyPushButton::MyPushButton
MyPushButton(QWidget *parent=nullptr)
Definition
main.cpp:15
MyPushButton::paintEvent
void paintEvent(QPaintEvent *) override
[0]
Definition
main.cpp:21
MyStyle
[0]
Definition
main.cpp:39
MyStyle::drawPrimitive
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget)
[4]
Definition
main.cpp:47
main
int main(int argc, char *argv[])
[ctor_close]
Definition
src_corelib_animation_qpropertyanimation.cpp:100
qtbase
src
widgets
doc
snippets
qstyleoption
main.cpp
Generated on
for Qt by
1.18.0