1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the documentation of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:BSD$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** BSD License Usage 18 ** Alternatively, you may use this file under the terms of the BSD license 19 ** as follows: 20 ** 21 ** "Redistribution and use in source and binary forms, with or without 22 ** modification, are permitted provided that the following conditions are 23 ** met: 24 ** * Redistributions of source code must retain the above copyright 25 ** notice, this list of conditions and the following disclaimer. 26 ** * Redistributions in binary form must reproduce the above copyright 27 ** notice, this list of conditions and the following disclaimer in 28 ** the documentation and/or other materials provided with the 29 ** distribution. 30 ** * Neither the name of The Qt Company Ltd nor the names of its 31 ** contributors may be used to endorse or promote products derived 32 ** from this software without specific prior written permission. 33 ** 34 ** 35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 ** 47 ** $QT_END_LICENSE$ 48 ** 49 ****************************************************************************/ 50 51 //! [21] 52 qApp->setStyleSheet("QPushButton { color: white }"); 53 //! [21] 54 55 56 //! [22] 57 myPushButton->setStyleSheet("* { color: blue }"); 58 //! [22] 59 60 61 //! [23] 62 myPushButton->setStyleSheet("color: blue"); 63 //! [23] 64 65 66 //! [24] 67 qApp->setStyleSheet("QGroupBox { color: red; } "); 68 //! [24] 69 70 //! [25] 71 qApp->setStyleSheet("QGroupBox, QGroupBox * { color: red; }"); 72 //! [25] 73 74 75 //! [26] 76 class MyPushButton : public QPushButton { 77 // ... 78 } 79 80 // ... 81 qApp->setStyleSheet("MyPushButton { background: yellow; }"); 82 //! [26] 83 84 85 //! [27] 86 namespace ns { 87 class MyPushButton : public QPushButton { 88 // ... 89 } 90 } 91 92 // ... 93 qApp->setStyleSheet("ns--MyPushButton { background: yellow; }"); 94 //! [27] 95 96 97 //! [32] 98 void CustomWidget::paintEvent(QPaintEvent *) 99 { 100 QStyleOption opt; 101 opt.init(this); 102 QPainter p(this); 103 style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); 104 } 105 //! [32] 106 107 108 //! [88] 109 qApp->setStyleSheet("QLineEdit { background-color: yellow }"); 110 //! [88] 111 112 113 //! [89] 114 myDialog->setStyleSheet("QLineEdit { background-color: yellow }"); 115 //! [89] 116 117 118 //! [90] 119 myDialog->setStyleSheet("QLineEdit#nameEdit { background-color: yellow }"); 120 //! [90] 121 122 123 //! [91] 124 nameEdit->setStyleSheet("background-color: yellow"); 125 //! [91] 126 127 128 //! [92] 129 nameEdit->setStyleSheet("color: blue; background-color: yellow"); 130 //! [92] 131 132 133 //! [93] 134 nameEdit->setStyleSheet("color: blue;" 135 "background-color: yellow;" 136 "selection-color: yellow;" 137 "selection-background-color: blue;"); 138 //! [93] 139 140 141 //! [95] 142 QLineEdit *nameEdit = new QLineEdit(this); 143 nameEdit->setProperty("mandatoryField", true); 144 145 QLineEdit *emailEdit = new QLineEdit(this); 146 emailEdit->setProperty("mandatoryField", true); 147 148 QSpinBox *ageSpinBox = new QSpinBox(this); 149 ageSpinBox->setProperty("mandatoryField", true); 150 //! [95] 151 152 //! [96] 153 QCoreApplication::setAttribute(Qt::AA_UseStyleSheetPropagationInWidgetStyles, true); 154 //! [96] 155