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#if QT_CONFIG(style_stylesheet)
21
22QT_BEGIN_NAMESPACE
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);
137 ADD_BASIC_SELECTOR;
138 ADD_SELECTOR;
139
140 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
141 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Base);
142 ADD_DECLARATION;
143
144 SET_PROPERTY("border"_L1, Border);
145 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
146 ADD_DECLARATION;
147
148 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
149 ADD_VALUE(QCss::Value::Identifier, QString::fromLatin1("background-color"));
150 ADD_DECLARATION;
151
152 ADD_STYLE_RULE;
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);
161 ADD_BASIC_SELECTOR;
162 ADD_SELECTOR;
163
164 SET_PROPERTY("border"_L1, Border);
165 ADD_VALUE(QCss::Value::KnownIdentifier, Value_None);
166 ADD_DECLARATION;
167
168 ADD_STYLE_RULE;
169 }
170
171 /*QFrame {
172 border: native;
173 }*/
174 {
175 SET_ELEMENT_NAME("QFrame"_L1);
176 ADD_BASIC_SELECTOR;
177 ADD_SELECTOR;
178
179 SET_PROPERTY("border"_L1, Border);
180 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
181 ADD_DECLARATION;
182
183 ADD_STYLE_RULE;
184 }
185
186 /*QLabel, QToolBox {
187 background: none;
188 border-image: none;
189 }*/
190 {
191 SET_ELEMENT_NAME("QLabel"_L1);
192 ADD_BASIC_SELECTOR;
193 ADD_SELECTOR;
194
195 SET_ELEMENT_NAME("QToolBox"_L1);
196 ADD_BASIC_SELECTOR;
197 ADD_SELECTOR;
198
199 SET_PROPERTY("background"_L1, Background);
200 ADD_VALUE(QCss::Value::KnownIdentifier, Value_None);
201 ADD_DECLARATION;
202
203 SET_PROPERTY("border-image"_L1, BorderImage);
204 ADD_VALUE(QCss::Value::KnownIdentifier, Value_None);
205 ADD_DECLARATION;
206
207 ADD_STYLE_RULE;
208 }
209
210 /*QGroupBox {
211 border: native;
212 }*/
213 {
214 SET_ELEMENT_NAME("QGroupBox"_L1);
215 ADD_BASIC_SELECTOR;
216 ADD_SELECTOR;
217
218 SET_PROPERTY("border"_L1, Border);
219 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
220 ADD_DECLARATION;
221
222 ADD_STYLE_RULE;
223 }
224
225
226 /*QToolTip {
227 -qt-background-role: window;
228 border: native;
229 }*/
230 {
231 SET_ELEMENT_NAME("QToolTip"_L1);
232 ADD_BASIC_SELECTOR;
233 ADD_SELECTOR;
234
235 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
236 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Window);
237 ADD_DECLARATION;
238
239 SET_PROPERTY("border"_L1, Border);
240 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
241 ADD_DECLARATION;
242
243 ADD_STYLE_RULE;
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);
252 ADD_BASIC_SELECTOR;
253 ADD_SELECTOR;
254
255 SET_ELEMENT_NAME("QToolButton"_L1);
256 ADD_BASIC_SELECTOR;
257 ADD_SELECTOR;
258
259 SET_PROPERTY("border-style"_L1, BorderStyles);
260 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
261 ADD_DECLARATION;
262
263 if (!styleIsPixmapBased) {
264 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
265 ADD_VALUE(QCss::Value::Identifier, QString::fromLatin1("background-color"));
266 ADD_DECLARATION;
267 }
268
269
270 ADD_STYLE_RULE;
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);
282 ADD_BASIC_SELECTOR;
283 ADD_SELECTOR;
284
285 SET_PROPERTY("border"_L1, Border);
286 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
287 ADD_DECLARATION;
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"));
293 ADD_DECLARATION;
294 }
295
296 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
297 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Base);
298 ADD_DECLARATION;
299
300 ADD_STYLE_RULE;
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);
313 ADD_BASIC_SELECTOR;
314 ADD_SELECTOR;
315
316 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
317 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Button);
318 ADD_DECLARATION;
319
320 ADD_STYLE_RULE;
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);
330 ADD_BASIC_SELECTOR;
331 ADD_SELECTOR;
332
333 SET_PROPERTY("border"_L1, Border);
334 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
335 ADD_DECLARATION;
336
337 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
338 ADD_VALUE(QCss::Value::Identifier, QString::fromLatin1("background-color"));
339 ADD_DECLARATION;
340
341 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
342 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Base);
343 ADD_DECLARATION;
344
345 ADD_STYLE_RULE;
346 }
347
348 /*QMenu {
349 -qt-background-role: window;
350 }*/
351 {
352 SET_ELEMENT_NAME("QMenu"_L1);
353 ADD_BASIC_SELECTOR;
354 ADD_SELECTOR;
355
356 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
357 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Window);
358 ADD_DECLARATION;
359
360 ADD_STYLE_RULE;
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);
368 ADD_BASIC_SELECTOR;
369 ADD_SELECTOR;
370
371 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
372 ADD_VALUE(QCss::Value::Identifier, QString::fromLatin1("background-color"));
373 ADD_DECLARATION;
374
375 ADD_STYLE_RULE;
376 }
377
378 /*QHeaderView {
379 -qt-background-role: window;
380 }*/
381 {
382 SET_ELEMENT_NAME("QHeaderView"_L1);
383 ADD_BASIC_SELECTOR;
384 ADD_SELECTOR;
385
386 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
387 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Window);
388 ADD_DECLARATION;
389
390 ADD_STYLE_RULE;
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);
401 ADD_BASIC_SELECTOR;
402 ADD_SELECTOR;
403
404 SET_ELEMENT_NAME("QHeaderView"_L1);
405 ADD_PSEUDO("section"_L1, PseudoClass_Unknown);
406 ADD_BASIC_SELECTOR;
407 ADD_SELECTOR;
408
409 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
410 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Button);
411 ADD_DECLARATION;
412
413 if (!styleIsPixmapBased) {
414 SET_PROPERTY("-qt-style-features"_L1, QtStyleFeatures);
415 ADD_VALUE(QCss::Value::Identifier, QString::fromLatin1("background-color"));
416 ADD_DECLARATION;
417 }
418
419 SET_PROPERTY("border"_L1, Border);
420 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
421 ADD_DECLARATION;
422
423 ADD_STYLE_RULE;
424 }
425
426 /*QProgressBar {
427 -qt-background-role: base;
428 }*/
429 {
430 SET_ELEMENT_NAME("QProgressBar"_L1);
431 ADD_BASIC_SELECTOR;
432 ADD_SELECTOR;
433
434 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
435 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Base);
436 ADD_DECLARATION;
437
438 ADD_STYLE_RULE;
439 }
440
441 /*QScrollBar {
442 -qt-background-role: window;
443 }*/
444 {
445 SET_ELEMENT_NAME("QScrollBar"_L1);
446 ADD_BASIC_SELECTOR;
447 ADD_SELECTOR;
448
449 SET_PROPERTY("-qt-background-role"_L1, QtBackgroundRole);
450 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Window);
451 ADD_DECLARATION;
452
453 ADD_STYLE_RULE;
454 }
455
456 /*QDockWidget {
457 border: native;
458 }*/
459 {
460 SET_ELEMENT_NAME("QDockWidget"_L1);
461 ADD_BASIC_SELECTOR;
462 ADD_SELECTOR;
463
464 SET_PROPERTY("border"_L1, Border);
465 ADD_VALUE(QCss::Value::KnownIdentifier, Value_Native);
466 ADD_DECLARATION;
467
468 ADD_STYLE_RULE;
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