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
doc_src_stylesheet.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
<
QtWidgets
>
5
#
include
<
QCoreApplication
>
6
7
void
examples
()
8
{
9
QPushButton *myPushButton;
10
11
{
12
//! [21]
13
qApp->setStyleSheet(
"QPushButton { color: white }"
);
14
//! [21]
15
}
16
17
{
18
//! [22]
19
myPushButton->setStyleSheet(
"* { color: blue }"
);
20
//! [22]
21
}
22
23
{
24
//! [23]
25
myPushButton->setStyleSheet(
"color: blue"
);
26
//! [23]
27
}
28
29
{
30
//! [24]
31
qApp->setStyleSheet(
"QGroupBox { color: red; } "
);
32
//! [24]
33
}
34
35
{
36
//! [25]
37
qApp->setStyleSheet(
"QGroupBox, QGroupBox * { color: red; }"
);
38
//! [25]
39
}
40
}
41
42
//! [26]
43
class
MyPushButton
:
public
QPushButton
{
44
// ...
45
};
46
47
// ...
48
void
someFunction
()
49
{
50
qApp->setStyleSheet(
"MyPushButton { background: yellow; }"
);
51
//...
52
//! [26]
53
}
54
55
//! [27]
56
namespace
ns
{
57
class
MyPushButton
:
public
QPushButton
{
58
// ...
59
};
60
}
61
62
// ...
63
void
someMethod
()
64
{
65
qApp->setStyleSheet(
"ns--MyPushButton { background: yellow; }"
);
66
//...
67
//! [27]
68
}
69
70
class
CustomWidget
:
public
QWidget
71
{
72
Q_OBJECT
73
public
:
74
void
wrap
();
75
void
paintEvent
(QPaintEvent *event)
override
;
76
private
:
77
QWidget *myDialog;
78
QWidget *nameEdit;
79
};
80
//! [32]
81
void
CustomWidget
::
paintEvent
(QPaintEvent *)
82
{
83
QStyleOption opt;
84
opt.initFrom(
this
);
85
QPainter p(
this
);
86
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p,
this
);
87
}
88
//! [32]
89
90
void
CustomWidget
::wrap()
91
{
92
{
93
//! [88]
94
qApp->setStyleSheet(
"QLineEdit { background-color: yellow }"
);
95
//! [88]
96
}
97
98
{
99
//! [89]
100
myDialog->setStyleSheet(
"QLineEdit { background-color: yellow }"
);
101
//! [89]
102
}
103
104
{
105
//! [90]
106
myDialog->setStyleSheet(
"QLineEdit#nameEdit { background-color: yellow }"
);
107
//! [90]
108
}
109
110
{
111
//! [91]
112
nameEdit->setStyleSheet(
"background-color: yellow"
);
113
//! [91]
114
}
115
116
{
117
//! [92]
118
nameEdit->setStyleSheet(
"color: blue; background-color: yellow"
);
119
//! [92]
120
}
121
122
{
123
//! [93]
124
nameEdit->setStyleSheet(
"color: blue;"
125
"background-color: yellow;"
126
"selection-color: yellow;"
127
"selection-background-color: blue;"
);
128
//! [93]
129
}
130
131
{
132
//! [95]
133
QLineEdit *nameEdit =
new
QLineEdit(
this
);
134
nameEdit->setProperty(
"mandatoryField"
,
true
);
135
136
QLineEdit *emailEdit =
new
QLineEdit(
this
);
137
emailEdit->setProperty(
"mandatoryField"
,
true
);
138
139
QSpinBox *ageSpinBox =
new
QSpinBox(
this
);
140
ageSpinBox->setProperty(
"mandatoryField"
,
true
);
141
//! [95]
142
}
143
144
{
145
//! [96]
146
QCoreApplication::setAttribute(Qt::AA_UseStyleSheetPropagationInWidgetStyles,
true
);
147
//! [96]
148
}
149
}
CustomWidget
Definition
doc_src_stylesheet.cpp:71
CustomWidget::paintEvent
void paintEvent(QPaintEvent *event) override
[32]
Definition
doc_src_stylesheet.cpp:81
MyPushButton
[26]
Definition
doc_src_stylesheet.cpp:43
ns::MyPushButton
Definition
doc_src_stylesheet.cpp:57
ns
[27]
Definition
doc_src_stylesheet.cpp:56
examples
bool examples()
[3]
Definition
src_corelib_global_qglobal.cpp:43
someFunction
void someFunction()
[10]
Definition
src_corelib_kernel_qmetatype.cpp:111
someMethod
void someMethod()
[11]
Definition
src_corelib_kernel_qmetatype.cpp:126
qtbase
src
widgets
doc
snippets
code
doc_src_stylesheet.cpp
Generated on
for Qt by
1.14.0