Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5qApp->setStyleSheet("QPushButton { color: white }");
7
8
10myPushButton->setStyleSheet("* { color: blue }");
12
13
15myPushButton->setStyleSheet("color: blue");
17
18
20qApp->setStyleSheet("QGroupBox { color: red; } ");
22
24qApp->setStyleSheet("QGroupBox, QGroupBox * { color: red; }");
26
27
29class MyPushButton : public QPushButton {
30 // ...
31}
32
33// ...
34qApp->setStyleSheet("MyPushButton { background: yellow; }");
36
37
39namespace ns {
40 class MyPushButton : public QPushButton {
41 // ...
42 }
43}
44
45// ...
46qApp->setStyleSheet("ns--MyPushButton { background: yellow; }");
48
49
51void CustomWidget::paintEvent(QPaintEvent *)
52{
54 opt.initFrom(this);
55 QPainter p(this);
56 style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
57}
59
60
62qApp->setStyleSheet("QLineEdit { background-color: yellow }");
64
65
67myDialog->setStyleSheet("QLineEdit { background-color: yellow }");
69
70
72myDialog->setStyleSheet("QLineEdit#nameEdit { background-color: yellow }");
74
75
77nameEdit->setStyleSheet("background-color: yellow");
79
80
82nameEdit->setStyleSheet("color: blue; background-color: yellow");
84
85
87nameEdit->setStyleSheet("color: blue;"
88 "background-color: yellow;"
89 "selection-color: yellow;"
90 "selection-background-color: blue;");
92
93
96nameEdit->setProperty("mandatoryField", true);
97
99emailEdit->setProperty("mandatoryField", true);
100
102ageSpinBox->setProperty("mandatoryField", true);
104
static void setAttribute(Qt::ApplicationAttribute attribute, bool on=true)
Sets the attribute attribute if on is true; otherwise clears the attribute.
The QLineEdit widget is a one-line text editor.
Definition qlineedit.h:28
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
The QPushButton widget provides a command button.
Definition qpushbutton.h:20
The QSpinBox class provides a spin box widget.
Definition qspinbox.h:16
The QStyleOption class stores the parameters used by QStyle functions.
void initFrom(const QWidget *w)
@ PE_Widget
Definition qstyle.h:148
void setStyleSheet(const QString &styleSheet)
Definition qwidget.cpp:2555
QStyleOptionButton opt
QLineEdit * nameEdit
[93]
QSpinBox * ageSpinBox
QLineEdit * emailEdit
@ AA_UseStyleSheetPropagationInWidgetStyles
Definition qnamespace.h:457
#define qApp
GLfloat GLfloat p
[1]