Qt 6.x
The Qt SDK
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
127
128 /*QLineEdit {
129 -qt-background-role: base;
130 border: native;
131 -qt-style-features: background-color;
132 }*/
133 {
134 SET_ELEMENT_NAME("QLineEdit"_L1);
137
138 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
141
142 SET_PROPERTY("border"_L1, Border);
145
146 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
149
151 }
152
153 /*QLineEdit:no-frame {
154 border: none;
155 }*/
156 {
157 SET_ELEMENT_NAME("QLineEdit"_L1);
158 ADD_PSEUDO("no-frame"_L1, PseudoClass_Frameless);
161
162 SET_PROPERTY("border"_L1, Border);
165
167 }
168
169 /*QFrame {
170 border: native;
171 }*/
172 {
173 SET_ELEMENT_NAME("QFrame"_L1);
176
177 SET_PROPERTY("border"_L1, Border);
180
182 }
183
184 /*QLabel, QToolBox {
185 background: none;
186 border-image: none;
187 }*/
188 {
189 SET_ELEMENT_NAME("QLabel"_L1);
192
193 SET_ELEMENT_NAME("QToolBox"_L1);
196
197 SET_PROPERTY("background"_L1, Background);
200
201 SET_PROPERTY("border-image"_L1, BorderImage);
204
206 }
207
208 /*QGroupBox {
209 border: native;
210 }*/
211 {
212 SET_ELEMENT_NAME("QGroupBox"_L1);
215
216 SET_PROPERTY("border"_L1, Border);
219
221 }
222
223
224 /*QToolTip {
225 -qt-background-role: window;
226 border: native;
227 }*/
228 {
229 SET_ELEMENT_NAME("QToolTip"_L1);
232
233 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
236
237 SET_PROPERTY("border"_L1, Border);
240
242 }
243
244 /*QPushButton, QToolButton {
245 border-style: native;
246 -qt-style-features: background-color; //only for not pixmap based styles
247 }*/
248 {
249 SET_ELEMENT_NAME("QPushButton"_L1);
252
253 SET_ELEMENT_NAME("QToolButton"_L1);
256
257 SET_PROPERTY("border-style"_L1, BorderStyles);
260
261 if (!styleIsPixmapBased) {
262 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
265 }
266
267
269 }
270
271
272 /*QComboBox {
273 border: native;
274 -qt-style-features: background-color background-gradient; //only for not pixmap based styles
275 -qt-background-role: base;
276 }*/
277
278 {
279 SET_ELEMENT_NAME("QComboBox"_L1);
282
283 SET_PROPERTY("border"_L1, Border);
286
287 if (!styleIsPixmapBased) {
288 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
292 }
293
294 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
297
299 }
300
301 /*QComboBox[style="QPlastiqueStyle"][readOnly="true"],
302 QComboBox[style="QFusionStyle"][readOnly="true"],
303 QComboBox[style="QCleanlooksStyle"][readOnly="true"]
304 {
305 -qt-background-role: button;
306 }*/
307 if (baseStyle()->inherits("QPlastiqueStyle") || baseStyle()->inherits("QCleanlooksStyle") || baseStyle()->inherits("QFusionStyle"))
308 {
309 SET_ELEMENT_NAME("QComboBox"_L1);
310 ADD_ATTRIBUTE_SELECTOR("readOnly"_L1, "true"_L1, AttributeSelector::MatchEqual);
313
314 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
317
319 }
320
321 /*QAbstractSpinBox {
322 border: native;
323 -qt-style-features: background-color;
324 -qt-background-role: base;
325 }*/
326 {
327 SET_ELEMENT_NAME("QAbstractSpinBox"_L1);
330
331 SET_PROPERTY("border"_L1, Border);
334
335 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
338
339 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
342
344 }
345
346 /*QMenu {
347 -qt-background-role: window;
348 }*/
349 {
350 SET_ELEMENT_NAME("QMenu"_L1);
353
354 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
357
359 }
360 /*QMenu::item {
361 -qt-style-features: background-color;
362 }*/
363 if (!styleIsPixmapBased) {
364 SET_ELEMENT_NAME("QMenu"_L1);
368
369 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
372
374 }
375
376 /*QHeaderView {
377 -qt-background-role: window;
378 }*/
379 {
380 SET_ELEMENT_NAME("QHeaderView"_L1);
383
384 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
387
389 }
390
391 /*QTableCornerButton::section, QHeaderView::section {
392 -qt-background-role: button;
393 -qt-style-features: background-color; //if style is not pixmap based
394 border: native;
395 }*/
396 {
397 SET_ELEMENT_NAME("QTableCornerButton"_L1);
398 ADD_PSEUDO("section"_L1, PseudoClass_Unknown);
401
402 SET_ELEMENT_NAME("QHeaderView"_L1);
403 ADD_PSEUDO("section"_L1, PseudoClass_Unknown);
406
407 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
410
411 if (!styleIsPixmapBased) {
412 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
415 }
416
417 SET_PROPERTY("border"_L1, Border);
420
422 }
423
424 /*QProgressBar {
425 -qt-background-role: base;
426 }*/
427 {
428 SET_ELEMENT_NAME("QProgressBar"_L1);
431
432 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
435
437 }
438
439 /*QScrollBar {
440 -qt-background-role: window;
441 }*/
442 {
443 SET_ELEMENT_NAME("QScrollBar"_L1);
446
447 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
450
452 }
453
454 /*QDockWidget {
455 border: native;
456 }*/
457 {
458 SET_ELEMENT_NAME("QDockWidget"_L1);
461
462 SET_PROPERTY("border"_L1, Border);
465
467 }
468
470 sheet.buildIndexes();
471 return sheet;
472}
473
474#endif // #ifndef QT_NO_STYLE_STYLESHEET
475
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:313
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5710
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")
Q_GUI_EXPORT void buildIndexes(Qt::CaseSensitivity nameCaseSensitivity=Qt::CaseSensitive)
StyleSheetOrigin origin