Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qstylesheetstyle_default.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
4/* This is the default Qt style sheet.
5
6 IMPORTANT: This style sheet is primarily meant for defining feature
7 capabilities of styles. Do NOT add default styling rules here. When in
8 doubt ask the stylesheet maintainer.
9
10 The stylesheet in here used to be in a CSS file, but was moved here to
11 avoid parsing overhead.
12*/
13
14#include "qstylesheetstyle_p.h"
15#if QT_CONFIG(cssparser)
16#include "private/qcssparser_p.h"
17#endif
18
19#ifndef QT_NO_STYLE_STYLESHEET
20
22
23using namespace Qt::StringLiterals;
24using namespace QCss;
25
26// This is the class name of the selector.
27// Use an empty string where you would use '*' in CSS.
28// Ex. QHeaderView
29
30#define SET_ELEMENT_NAME(x) \
31 bSelector.elementName = (x)
32
33// This acts as both pseudo state and sub control. The first parameter is the
34// string name, and the second is the PseudoClass_* constant.
35// The sub control specifier is always the first, and has the type
36// PseudoClass_Unknown.
37// If there is no PseudoClass_Unknown as the first pseudo, it is assumed to be
38// a pseudo state.
39// Ex. QComboBox::drop-down:enabled
40// ^ ^
41
42#define ADD_PSEUDO(x, y) \
43 pseudo.type = (y); \
44 pseudo.name = (x); \
45 bSelector.pseudos << pseudo
46
47// This is attributes. The third parameter is AttributeSelector::*
48// Ex. QComboBox[style="QWindowsVistaStyle"]
49// ^ ^
50
51#define ADD_ATTRIBUTE_SELECTOR(x, y, z) \
52 attr.name = (x); \
53 attr.value = (y); \
54 attr.valueMatchCriterium = (z); \
55 bSelector.attributeSelectors << attr
56
57// Adds the current basic selector to the rule.
58// Several basic selectors behave as AND (space in CSS).
59
60#define ADD_BASIC_SELECTOR \
61 selector.basicSelectors << bSelector; \
62 bSelector.ids.clear(); \
63 bSelector.pseudos.clear(); \
64 bSelector.attributeSelectors.clear()
65
66// Adds the current selector to the rule.
67// Several selectors behave as OR (comma in CSS).
68
69#define ADD_SELECTOR \
70 styleRule.selectors << selector; \
71 selector.basicSelectors.clear()
72
73// Sets the name of a property.
74// Ex. background: red;
75// ^
76
77#define SET_PROPERTY(x, y) \
78 decl.d->property = (x); \
79 decl.d->propertyId = (y)
80
81// Adds a value to the current property.
82// The first parameter should be Value::KnownIdentifier if the value can be
83// found among the Value_* constants, in which case the second should be that
84// constant. Otherwise the first parameter is Value::Identifier and the second
85// is a string.
86// Adding more values is the same as separating by spaces in CSS.
87// Ex. border: 2px solid black;
88// ^ ^ ^
89
90#define ADD_VALUE(x, y) \
91 value.type = (x); \
92 value.variant = (y); \
93 decl.d->values << value
94
95// Adds the current declaration to the rule.
96// Ex. border: 2px solid black;
97// \----------------------/
98
99#define ADD_DECLARATION \
100 styleRule.declarations << decl; \
101 decl.d.detach(); \
102 decl.d->values.clear()
103
104// Adds the rule to the stylesheet.
105// Use at the end of every CSS block.
106
107#define ADD_STYLE_RULE \
108 sheet.styleRules << styleRule; \
109 styleRule.selectors.clear(); \
110 styleRule.declarations.clear()
111
112StyleSheet QStyleSheetStyle::getDefaultStyleSheet() const
113{
114 StyleSheet sheet;
115 StyleRule styleRule;
116 BasicSelector bSelector;
118 Declaration decl;
120 Pseudo pseudo;
122
123 // pixmap based style doesn't support any features
124 bool styleIsPixmapBased = baseStyle()->inherits("QMacStyle")
125 || (baseStyle()->inherits("QWindowsVistaStyle")
126 && !baseStyle()->inherits("QWindows11Style"));
127
128
129 /*QLineEdit {
130 -qt-background-role: base;
131 border: native;
132 -qt-style-features: background-color;
133 }*/
134 {
135 SET_ELEMENT_NAME("QLineEdit"_L1);
138
139 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
142
143 SET_PROPERTY("border"_L1, Border);
146
147 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
150
152 }
153
154 /*QLineEdit:no-frame {
155 border: none;
156 }*/
157 {
158 SET_ELEMENT_NAME("QLineEdit"_L1);
159 ADD_PSEUDO("no-frame"_L1, PseudoClass_Frameless);
162
163 SET_PROPERTY("border"_L1, Border);
166
168 }
169
170 /*QFrame {
171 border: native;
172 }*/
173 {
174 SET_ELEMENT_NAME("QFrame"_L1);
177
178 SET_PROPERTY("border"_L1, Border);
181
183 }
184
185 /*QLabel, QToolBox {
186 background: none;
187 border-image: none;
188 }*/
189 {
190 SET_ELEMENT_NAME("QLabel"_L1);
193
194 SET_ELEMENT_NAME("QToolBox"_L1);
197
198 SET_PROPERTY("background"_L1, Background);
201
202 SET_PROPERTY("border-image"_L1, BorderImage);
205
207 }
208
209 /*QGroupBox {
210 border: native;
211 }*/
212 {
213 SET_ELEMENT_NAME("QGroupBox"_L1);
216
217 SET_PROPERTY("border"_L1, Border);
220
222 }
223
224
225 /*QToolTip {
226 -qt-background-role: window;
227 border: native;
228 }*/
229 {
230 SET_ELEMENT_NAME("QToolTip"_L1);
233
234 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
237
238 SET_PROPERTY("border"_L1, Border);
241
243 }
244
245 /*QPushButton, QToolButton {
246 border-style: native;
247 -qt-style-features: background-color; //only for not pixmap based styles
248 }*/
249 {
250 SET_ELEMENT_NAME("QPushButton"_L1);
253
254 SET_ELEMENT_NAME("QToolButton"_L1);
257
258 SET_PROPERTY("border-style"_L1, BorderStyles);
261
262 if (!styleIsPixmapBased) {
263 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
266 }
267
268
270 }
271
272
273 /*QComboBox {
274 border: native;
275 -qt-style-features: background-color background-gradient; //only for not pixmap based styles
276 -qt-background-role: base;
277 }*/
278
279 {
280 SET_ELEMENT_NAME("QComboBox"_L1);
283
284 SET_PROPERTY("border"_L1, Border);
287
288 if (!styleIsPixmapBased) {
289 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
293 }
294
295 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
298
300 }
301
302 /*QComboBox[style="QPlastiqueStyle"][readOnly="true"],
303 QComboBox[style="QFusionStyle"][readOnly="true"],
304 QComboBox[style="QCleanlooksStyle"][readOnly="true"]
305 {
306 -qt-background-role: button;
307 }*/
308 if (baseStyle()->inherits("QPlastiqueStyle") || baseStyle()->inherits("QCleanlooksStyle") || baseStyle()->inherits("QFusionStyle"))
309 {
310 SET_ELEMENT_NAME("QComboBox"_L1);
311 ADD_ATTRIBUTE_SELECTOR("readOnly"_L1, "true"_L1, AttributeSelector::MatchEqual);
314
315 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
318
320 }
321
322 /*QAbstractSpinBox {
323 border: native;
324 -qt-style-features: background-color;
325 -qt-background-role: base;
326 }*/
327 {
328 SET_ELEMENT_NAME("QAbstractSpinBox"_L1);
331
332 SET_PROPERTY("border"_L1, Border);
335
336 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
339
340 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
343
345 }
346
347 /*QMenu {
348 -qt-background-role: window;
349 }*/
350 {
351 SET_ELEMENT_NAME("QMenu"_L1);
354
355 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
358
360 }
361 /*QMenu::item {
362 -qt-style-features: background-color;
363 }*/
364 if (!styleIsPixmapBased) {
365 SET_ELEMENT_NAME("QMenu"_L1);
369
370 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
373
375 }
376
377 /*QHeaderView {
378 -qt-background-role: window;
379 }*/
380 {
381 SET_ELEMENT_NAME("QHeaderView"_L1);
384
385 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
388
390 }
391
392 /*QTableCornerButton::section, QHeaderView::section {
393 -qt-background-role: button;
394 -qt-style-features: background-color; //if style is not pixmap based
395 border: native;
396 }*/
397 {
398 SET_ELEMENT_NAME("QTableCornerButton"_L1);
399 ADD_PSEUDO("section"_L1, PseudoClass_Unknown);
402
403 SET_ELEMENT_NAME("QHeaderView"_L1);
404 ADD_PSEUDO("section"_L1, PseudoClass_Unknown);
407
408 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
411
412 if (!styleIsPixmapBased) {
413 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
416 }
417
418 SET_PROPERTY("border"_L1, Border);
421
423 }
424
425 /*QProgressBar {
426 -qt-background-role: base;
427 }*/
428 {
429 SET_ELEMENT_NAME("QProgressBar"_L1);
432
433 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
436
438 }
439
440 /*QScrollBar {
441 -qt-background-role: window;
442 }*/
443 {
444 SET_ELEMENT_NAME("QScrollBar"_L1);
447
448 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
451
453 }
454
455 /*QDockWidget {
456 border: native;
457 }*/
458 {
459 SET_ELEMENT_NAME("QDockWidget"_L1);
462
463 SET_PROPERTY("border"_L1, Border);
466
468 }
469
470 sheet.origin = StyleSheetOrigin_UserAgent;
471 sheet.buildIndexes();
472 return sheet;
473}
474
475#endif // #ifndef QT_NO_STYLE_STYLESHEET
476
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition qobject.h:348
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
QStyle * baseStyle() const
const quint64 PseudoClass_Unknown
const quint64 PseudoClass_Frameless
@ Value_Button
@ Value_Base
@ Value_Native
@ Value_None
@ Value_Window
@ BorderImage
@ QtStyleFeatures
@ QtBackgroundRole
@ BorderStyles
@ Background
@ StyleSheetOrigin_UserAgent
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define ADD_VALUE(x, y)
#define ADD_ATTRIBUTE_SELECTOR(x, y, z)
#define ADD_SELECTOR
#define SET_ELEMENT_NAME(x)
#define ADD_STYLE_RULE
#define ADD_DECLARATION
#define SET_PROPERTY(x, y)
#define ADD_PSEUDO(x, y)
#define ADD_BASIC_SELECTOR
QFileSelector selector
[1]
timer inherits("QTimer")