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
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// Qt-Security score:significant reason:default
4
5/* This is the default Qt style sheet.
6
7 IMPORTANT: This style sheet is primarily meant for defining feature
8 capabilities of styles. Do NOT add default styling rules here. When in
9 doubt ask the stylesheet maintainer.
10
11 The stylesheet in here used to be in a CSS file, but was moved here to
12 avoid parsing overhead.
13*/
14
16#if QT_CONFIG(cssparser)
17#include "private/qcssparser_p.h"
18#endif
19
20#ifndef QT_NO_STYLE_STYLESHEET
21
23
24using namespace Qt::StringLiterals;
25using namespace QCss;
26
27// This is the class name of the selector.
28// Use an empty string where you would use '*' in CSS.
29// Ex. QHeaderView
30
31#define SET_ELEMENT_NAME(x)
32 bSelector.elementName = (x)
33
34// This acts as both pseudo state and sub control. The first parameter is the
35// string name, and the second is the PseudoClass_* constant.
36// The sub control specifier is always the first, and has the type
37// PseudoClass_Unknown.
38// If there is no PseudoClass_Unknown as the first pseudo, it is assumed to be
39// a pseudo state.
40// Ex. QComboBox::drop-down:enabled
41// ^ ^
42
43#define ADD_PSEUDO(x, y)
44 pseudo.type = (y);
45 pseudo.name = (x);
46 bSelector.pseudos << pseudo
47
48// This is attributes. The third parameter is AttributeSelector::*
49// Ex. QComboBox[style="QWindowsVistaStyle"]
50// ^ ^
51
52#define ADD_ATTRIBUTE_SELECTOR(x, y, z)
53 attr.name = (x);
54 attr.value = (y);
55 attr.valueMatchCriterium = (z);
56 bSelector.attributeSelectors << attr
57
58// Adds the current basic selector to the rule.
59// Several basic selectors behave as AND (space in CSS).
60
61#define ADD_BASIC_SELECTOR
62 selector.basicSelectors << bSelector;
63 bSelector.ids.clear();
64 bSelector.pseudos.clear();
65 bSelector.attributeSelectors.clear()
66
67// Adds the current selector to the rule.
68// Several selectors behave as OR (comma in CSS).
69
70#define ADD_SELECTOR
71 styleRule.selectors << selector;
72 selector.basicSelectors.clear()
73
74// Sets the name of a property.
75// Ex. background: red;
76// ^
77
78#define SET_PROPERTY(x, y)
79 decl.d->property = (x);
80 decl.d->propertyId = (y)
81
82// Adds a value to the current property.
83// The first parameter should be Value::KnownIdentifier if the value can be
84// found among the Value_* constants, in which case the second should be that
85// constant. Otherwise the first parameter is Value::Identifier and the second
86// is a string.
87// Adding more values is the same as separating by spaces in CSS.
88// Ex. border: 2px solid black;
89// ^ ^ ^
90
91#define ADD_VALUE(x, y)
92 value.type = (x);
93 value.variant = (y);
94 decl.d->values << value
95
96// Adds the current declaration to the rule.
97// Ex. border: 2px solid black;
98// \----------------------/
99
100#define ADD_DECLARATION
101 styleRule.declarations << decl;
102 decl.d.detach();
103 decl.d->values.clear()
104
105// Adds the rule to the stylesheet.
106// Use at the end of every CSS block.
107
108#define ADD_STYLE_RULE
109 sheet.styleRules << styleRule;
110 styleRule.selectors.clear();
111 styleRule.declarations.clear()
112
113StyleSheet QStyleSheetStyle::getDefaultStyleSheet() const
114{
115 StyleSheet sheet;
116 StyleRule styleRule;
117 BasicSelector bSelector;
118 Selector selector;
119 Declaration decl;
120 QCss::Value value;
121 Pseudo pseudo;
122 AttributeSelector attr;
123
124 // pixmap based style doesn't support any features
125 bool styleIsPixmapBased = baseStyle()->inherits("QMacStyle")
126 || (baseStyle()->inherits("QWindowsVistaStyle")
127 && !baseStyle()->inherits("QWindows11Style"));
128
129
130 /*QLineEdit {
131 -qt-background-role: base;
132 border: native;
133 -qt-style-features: background-color;
134 }*/
135 {
136 SET_ELEMENT_NAME("QLineEdit"_L1);
139
140 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
141 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Base);
143
144 SET_PROPERTY("border"_L1, Border);
145 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
147
148 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
149 ADD_VALUE(QCss::Value::Identifier, QString::fromLatin1("background-color"));
151
153 }
154
155 /*QLineEdit:no-frame {
156 border: none;
157 }*/
158 {
159 SET_ELEMENT_NAME("QLineEdit"_L1);
160 ADD_PSEUDO("no-frame"_L1, PseudoClass_Frameless);
163
164 SET_PROPERTY("border"_L1, Border);
165 ADD_VALUE(QCss::Value::KnownIdentifier, Value_None);
167
169 }
170
171 /*QFrame {
172 border: native;
173 }*/
174 {
175 SET_ELEMENT_NAME("QFrame"_L1);
178
179 SET_PROPERTY("border"_L1, Border);
180 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
182
184 }
185
186 /*QLabel, QToolBox {
187 background: none;
188 border-image: none;
189 }*/
190 {
191 SET_ELEMENT_NAME("QLabel"_L1);
194
195 SET_ELEMENT_NAME("QToolBox"_L1);
198
199 SET_PROPERTY("background"_L1, Background);
200 ADD_VALUE(QCss::Value::KnownIdentifier, Value_None);
202
203 SET_PROPERTY("border-image"_L1, BorderImage);
204 ADD_VALUE(QCss::Value::KnownIdentifier, Value_None);
206
208 }
209
210 /*QGroupBox {
211 border: native;
212 }*/
213 {
214 SET_ELEMENT_NAME("QGroupBox"_L1);
217
218 SET_PROPERTY("border"_L1, Border);
219 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
221
223 }
224
225
226 /*QToolTip {
227 -qt-background-role: window;
228 border: native;
229 }*/
230 {
231 SET_ELEMENT_NAME("QToolTip"_L1);
234
235 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
236 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Window);
238
239 SET_PROPERTY("border"_L1, Border);
240 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
242
244 }
245
246 /*QPushButton, QToolButton {
247 border-style: native;
248 -qt-style-features: background-color; //only for not pixmap based styles
249 }*/
250 {
251 SET_ELEMENT_NAME("QPushButton"_L1);
254
255 SET_ELEMENT_NAME("QToolButton"_L1);
258
259 SET_PROPERTY("border-style"_L1, BorderStyles);
260 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
262
263 if (!styleIsPixmapBased) {
264 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
265 ADD_VALUE(QCss::Value::Identifier, QString::fromLatin1("background-color"));
267 }
268
269
271 }
272
273
274 /*QComboBox {
275 border: native;
276 -qt-style-features: background-color background-gradient; //only for not pixmap based styles
277 -qt-background-role: base;
278 }*/
279
280 {
281 SET_ELEMENT_NAME("QComboBox"_L1);
284
285 SET_PROPERTY("border"_L1, Border);
286 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
288
289 if (!styleIsPixmapBased) {
290 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
291 ADD_VALUE(QCss::Value::Identifier, QString::fromLatin1("background-color"));
292 ADD_VALUE(QCss::Value::Identifier, QString::fromLatin1("background-gradient"));
294 }
295
296 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
297 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Base);
299
301 }
302
303 /*QComboBox[style="QPlastiqueStyle"][readOnly="true"],
304 QComboBox[style="QFusionStyle"][readOnly="true"],
305 QComboBox[style="QCleanlooksStyle"][readOnly="true"]
306 {
307 -qt-background-role: button;
308 }*/
309 if (baseStyle()->inherits("QFusionStyle"))
310 {
311 SET_ELEMENT_NAME("QComboBox"_L1);
312 ADD_ATTRIBUTE_SELECTOR("readOnly"_L1, "true"_L1, AttributeSelector::MatchEqual);
315
316 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
317 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Button);
319
321 }
322
323 /*QAbstractSpinBox {
324 border: native;
325 -qt-style-features: background-color;
326 -qt-background-role: base;
327 }*/
328 {
329 SET_ELEMENT_NAME("QAbstractSpinBox"_L1);
332
333 SET_PROPERTY("border"_L1, Border);
334 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
336
337 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
338 ADD_VALUE(QCss::Value::Identifier, QString::fromLatin1("background-color"));
340
341 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
342 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Base);
344
346 }
347
348 /*QMenu {
349 -qt-background-role: window;
350 }*/
351 {
352 SET_ELEMENT_NAME("QMenu"_L1);
355
356 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
357 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Window);
359
361 }
362 /*QMenu::item {
363 -qt-style-features: background-color;
364 }*/
365 if (!styleIsPixmapBased) {
366 SET_ELEMENT_NAME("QMenu"_L1);
367 ADD_PSEUDO("item"_L1, PseudoClass_Unknown);
370
371 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
372 ADD_VALUE(QCss::Value::Identifier, QString::fromLatin1("background-color"));
374
376 }
377
378 /*QHeaderView {
379 -qt-background-role: window;
380 }*/
381 {
382 SET_ELEMENT_NAME("QHeaderView"_L1);
385
386 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
387 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Window);
389
391 }
392
393 /*QTableCornerButton::section, QHeaderView::section {
394 -qt-background-role: button;
395 -qt-style-features: background-color; //if style is not pixmap based
396 border: native;
397 }*/
398 {
399 SET_ELEMENT_NAME("QTableCornerButton"_L1);
400 ADD_PSEUDO("section"_L1, PseudoClass_Unknown);
403
404 SET_ELEMENT_NAME("QHeaderView"_L1);
405 ADD_PSEUDO("section"_L1, PseudoClass_Unknown);
408
409 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
410 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Button);
412
413 if (!styleIsPixmapBased) {
414 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
415 ADD_VALUE(QCss::Value::Identifier, QString::fromLatin1("background-color"));
417 }
418
419 SET_PROPERTY("border"_L1, Border);
420 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
422
424 }
425
426 /*QProgressBar {
427 -qt-background-role: base;
428 }*/
429 {
430 SET_ELEMENT_NAME("QProgressBar"_L1);
433
434 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
435 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Base);
437
439 }
440
441 /*QScrollBar {
442 -qt-background-role: window;
443 }*/
444 {
445 SET_ELEMENT_NAME("QScrollBar"_L1);
448
449 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
450 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Window);
452
454 }
455
456 /*QDockWidget {
457 border: native;
458 }*/
459 {
460 SET_ELEMENT_NAME("QDockWidget"_L1);
463
464 SET_PROPERTY("border"_L1, Border);
465 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
467
469 }
470
471 sheet.origin = StyleSheetOrigin_UserAgent;
472 sheet.buildIndexes();
473 return sheet;
474}
475
476#endif // #ifndef QT_NO_STYLE_STYLESHEET
477
478QT_END_NAMESPACE
Combined button and popup list for selecting options.
#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