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