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
qquicksystempalette.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qquicksystempalette_p.h"
6
7
#
include
<
QEvent
>
8
#
include
<
QGuiApplication
>
9
#
include
<
QStyleHints
>
10
11
#
include
<
private
/
qobject_p
.
h
>
12
13
QT_BEGIN_NAMESPACE
14
15
class
QQuickSystemPalettePrivate
:
public
QObjectPrivate
16
{
17
public
:
18
QPalette
::
ColorGroup
group
;
19
};
20
21
22
23
/*!
24
\qmltype SystemPalette
25
\nativetype QQuickSystemPalette
26
\inqmlmodule QtQuick
27
\ingroup qtquick-visual-utility
28
\brief Provides access to the Qt palettes.
29
30
The SystemPalette type provides access to the Qt application
31
palettes. This provides information about the standard colors used
32
for application windows, buttons and other features. These colors
33
are grouped into three \e {color groups}: \c active, \c inactive,
34
and \c disabled. See the QPalette documentation for details about
35
color groups and the properties provided by SystemPalette.
36
37
This can be used to color items in a way that provides a more
38
native look and feel.
39
40
The following example creates a palette from the \c Active color
41
group and uses this to color the window and text items
42
appropriately:
43
44
\snippet qml/systempalette.qml 0
45
46
\sa QPalette
47
*/
48
QQuickSystemPalette::QQuickSystemPalette(QObject *parent)
49
: QObject(*(
new
QQuickSystemPalettePrivate), parent)
50
{
51
Q_D(QQuickSystemPalette);
52
d->group = QPalette::Active;
53
qGuiApp->styleHints()->installEventFilter(
this
);
54
}
55
56
/*!
57
\qmlproperty color QtQuick::SystemPalette::window
58
The window (general background) color of the current color group.
59
60
\sa QPalette::ColorRole
61
*/
62
QColor QQuickSystemPalette::window()
const
63
{
64
Q_D(
const
QQuickSystemPalette);
65
return
QGuiApplication::palette().color(d->group, QPalette::Window);
66
}
67
68
/*!
69
\qmlproperty color QtQuick::SystemPalette::windowText
70
The window text (general foreground) color of the current color group.
71
72
\sa QPalette::ColorRole
73
*/
74
QColor QQuickSystemPalette::windowText()
const
75
{
76
Q_D(
const
QQuickSystemPalette);
77
return
QGuiApplication::palette().color(d->group, QPalette::WindowText);
78
}
79
80
/*!
81
\qmlproperty color QtQuick::SystemPalette::base
82
The base color of the current color group.
83
84
\sa QPalette::ColorRole
85
*/
86
QColor QQuickSystemPalette::base()
const
87
{
88
Q_D(
const
QQuickSystemPalette);
89
return
QGuiApplication::palette().color(d->group, QPalette::Base);
90
}
91
92
/*!
93
\qmlproperty color QtQuick::SystemPalette::text
94
The text color of the current color group.
95
96
\sa QPalette::ColorRole
97
*/
98
QColor QQuickSystemPalette::text()
const
99
{
100
Q_D(
const
QQuickSystemPalette);
101
return
QGuiApplication::palette().color(d->group, QPalette::Text);
102
}
103
104
/*!
105
\qmlproperty color QtQuick::SystemPalette::alternateBase
106
The alternate base color of the current color group.
107
108
\sa QPalette::ColorRole
109
*/
110
QColor QQuickSystemPalette::alternateBase()
const
111
{
112
Q_D(
const
QQuickSystemPalette);
113
return
QGuiApplication::palette().color(d->group, QPalette::AlternateBase);
114
}
115
116
/*!
117
\qmlproperty color QtQuick::SystemPalette::button
118
The button color of the current color group.
119
120
\sa QPalette::ColorRole
121
*/
122
QColor QQuickSystemPalette::button()
const
123
{
124
Q_D(
const
QQuickSystemPalette);
125
return
QGuiApplication::palette().color(d->group, QPalette::Button);
126
}
127
128
/*!
129
\qmlproperty color QtQuick::SystemPalette::buttonText
130
The button text foreground color of the current color group.
131
132
\sa QPalette::ColorRole
133
*/
134
QColor QQuickSystemPalette::buttonText()
const
135
{
136
Q_D(
const
QQuickSystemPalette);
137
return
QGuiApplication::palette().color(d->group, QPalette::ButtonText);
138
}
139
140
/*!
141
\qmlproperty color QtQuick::SystemPalette::light
142
The light color of the current color group.
143
144
\sa QPalette::ColorRole
145
*/
146
QColor QQuickSystemPalette::light()
const
147
{
148
Q_D(
const
QQuickSystemPalette);
149
return
QGuiApplication::palette().color(d->group, QPalette::Light);
150
}
151
152
/*!
153
\qmlproperty color QtQuick::SystemPalette::midlight
154
The midlight color of the current color group.
155
156
\sa QPalette::ColorRole
157
*/
158
QColor QQuickSystemPalette::midlight()
const
159
{
160
Q_D(
const
QQuickSystemPalette);
161
return
QGuiApplication::palette().color(d->group, QPalette::Midlight);
162
}
163
164
/*!
165
\qmlproperty color QtQuick::SystemPalette::dark
166
The dark color of the current color group.
167
168
\sa QPalette::ColorRole
169
*/
170
QColor QQuickSystemPalette::dark()
const
171
{
172
Q_D(
const
QQuickSystemPalette);
173
return
QGuiApplication::palette().color(d->group, QPalette::Dark);
174
}
175
176
/*!
177
\qmlproperty color QtQuick::SystemPalette::mid
178
The mid color of the current color group.
179
180
\sa QPalette::ColorRole
181
*/
182
QColor QQuickSystemPalette::mid()
const
183
{
184
Q_D(
const
QQuickSystemPalette);
185
return
QGuiApplication::palette().color(d->group, QPalette::Mid);
186
}
187
188
/*!
189
\qmlproperty color QtQuick::SystemPalette::shadow
190
The shadow color of the current color group.
191
192
\sa QPalette::ColorRole
193
*/
194
QColor QQuickSystemPalette::shadow()
const
195
{
196
Q_D(
const
QQuickSystemPalette);
197
return
QGuiApplication::palette().color(d->group, QPalette::Shadow);
198
}
199
200
/*!
201
\qmlproperty color QtQuick::SystemPalette::highlight
202
The highlight color of the current color group.
203
204
\sa QPalette::ColorRole
205
*/
206
QColor QQuickSystemPalette::highlight()
const
207
{
208
Q_D(
const
QQuickSystemPalette);
209
return
QGuiApplication::palette().color(d->group, QPalette::Highlight);
210
}
211
212
/*!
213
\qmlproperty color QtQuick::SystemPalette::highlightedText
214
The highlighted text color of the current color group.
215
216
\sa QPalette::ColorRole
217
*/
218
QColor QQuickSystemPalette::highlightedText()
const
219
{
220
Q_D(
const
QQuickSystemPalette);
221
return
QGuiApplication::palette().color(d->group, QPalette::HighlightedText);
222
}
223
224
/*!
225
\qmlproperty color QtQuick::SystemPalette::placeholderText
226
The placeholder text color of the current color group.
227
228
\since 6.2
229
\sa QPalette::ColorRole
230
*/
231
QColor QQuickSystemPalette::placeholderText()
const
232
{
233
Q_D(
const
QQuickSystemPalette);
234
return
QGuiApplication::palette().color(d->group, QPalette::PlaceholderText);
235
}
236
237
/*!
238
\qmlproperty color QtQuick::SystemPalette::accent
239
The accent color of the current color group.
240
241
\since 6.7
242
\sa QPalette::ColorRole
243
*/
244
QColor QQuickSystemPalette::accent()
const
245
{
246
Q_D(
const
QQuickSystemPalette);
247
return
QGuiApplication::palette().color(d->group, QPalette::Accent);
248
}
249
250
/*!
251
\qmlproperty enumeration QtQuick::SystemPalette::colorGroup
252
253
The color group of the palette. This can be one of:
254
255
\value SystemPalette.Active (default) QPalette::Active
256
\value SystemPalette.Inactive QPalette::Inactive
257
\value SystemPalette.Disabled QPalette::Disabled
258
259
\sa QPalette::ColorGroup
260
*/
261
QQuickSystemPalette::ColorGroup QQuickSystemPalette::colorGroup()
const
262
{
263
Q_D(
const
QQuickSystemPalette);
264
return
(QQuickSystemPalette::ColorGroup)d->group;
265
}
266
267
void
QQuickSystemPalette::setColorGroup(QQuickSystemPalette::ColorGroup colorGroup)
268
{
269
Q_D(QQuickSystemPalette);
270
d->group = (QPalette::ColorGroup)colorGroup;
271
emit paletteChanged();
272
}
273
274
bool
QQuickSystemPalette::eventFilter(QObject *watched, QEvent *event)
275
{
276
if
(watched == qGuiApp->styleHints()
277
&& event->type() == QEvent::ApplicationPaletteChange) {
278
emit paletteChanged();
279
return
false
;
280
}
281
return
QObject::eventFilter(watched, event);
282
}
283
284
QT_END_NAMESPACE
285
286
#
include
"moc_qquicksystempalette_p.cpp"
QQuickSystemPalettePrivate
Definition
qquicksystempalette.cpp:16
QQuickSystemPalettePrivate::group
QPalette::ColorGroup group
Definition
qquicksystempalette.cpp:18
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quick
util
qquicksystempalette.cpp
Generated on
for Qt by
1.18.0