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
doc_src_stylesheet.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4//! [21]
5qApp->setStyleSheet("QPushButton { color: white }");
6//! [21]
7
8
9//! [22]
10myPushButton->setStyleSheet("* { color: blue }");
11//! [22]
12
13
14//! [23]
15myPushButton->setStyleSheet("color: blue");
16//! [23]
17
18
19//! [24]
20qApp->setStyleSheet("QGroupBox { color: red; } ");
21//! [24]
22
23//! [25]
24qApp->setStyleSheet("QGroupBox, QGroupBox * { color: red; }");
25//! [25]
26
27
28//! [26]
29class MyPushButton : public QPushButton {
30 // ...
31}
32
33// ...
34qApp->setStyleSheet("MyPushButton { background: yellow; }");
35//! [26]
36
37
38//! [27]
39namespace ns {
40 class MyPushButton : public QPushButton {
41 // ...
42 }
43}
44
45// ...
46qApp->setStyleSheet("ns--MyPushButton { background: yellow; }");
47//! [27]
48
49
50//! [32]
51void CustomWidget::paintEvent(QPaintEvent *)
52{
53 QStyleOption opt;
54 opt.initFrom(this);
55 QPainter p(this);
56 style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
57}
58//! [32]
59
60
61//! [88]
62qApp->setStyleSheet("QLineEdit { background-color: yellow }");
63//! [88]
64
65
66//! [89]
67myDialog->setStyleSheet("QLineEdit { background-color: yellow }");
68//! [89]
69
70
71//! [90]
72myDialog->setStyleSheet("QLineEdit#nameEdit { background-color: yellow }");
73//! [90]
74
75
76//! [91]
77nameEdit->setStyleSheet("background-color: yellow");
78//! [91]
79
80
81//! [92]
82nameEdit->setStyleSheet("color: blue; background-color: yellow");
83//! [92]
84
85
86//! [93]
87nameEdit->setStyleSheet("color: blue;"
88 "background-color: yellow;"
89 "selection-color: yellow;"
90 "selection-background-color: blue;");
91//! [93]
92
93
94//! [95]
95QLineEdit *nameEdit = new QLineEdit(this);
96nameEdit->setProperty("mandatoryField", true);
97
98QLineEdit *emailEdit = new QLineEdit(this);
99emailEdit->setProperty("mandatoryField", true);
100
101QSpinBox *ageSpinBox = new QSpinBox(this);
102ageSpinBox->setProperty("mandatoryField", true);
103//! [95]
104
105//! [96]
106QCoreApplication::setAttribute(Qt::AA_UseStyleSheetPropagationInWidgetStyles, true);
107//! [96]
QLineEdit * emailEdit
QLineEdit * nameEdit
[93]
QSpinBox * ageSpinBox