|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the documentation of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtGui> |
|
43 #include <QApplication> |
|
44 |
|
45 class MyPushButton : public QPushButton |
|
46 { |
|
47 public: |
|
48 MyPushButton(QWidget *parent = 0); |
|
49 |
|
50 void paintEvent(QPaintEvent *); |
|
51 }; |
|
52 |
|
53 MyPushButton::MyPushButton(QWidget *parent) |
|
54 : QPushButton(parent) |
|
55 { |
|
56 } |
|
57 |
|
58 //! [0] |
|
59 void MyPushButton::paintEvent(QPaintEvent *) |
|
60 { |
|
61 QStyleOptionButton option; |
|
62 option.initFrom(this); |
|
63 option.state = isDown() ? QStyle::State_Sunken : QStyle::State_Raised; |
|
64 if (isDefault()) |
|
65 option.features |= QStyleOptionButton::DefaultButton; |
|
66 option.text = text(); |
|
67 option.icon = icon(); |
|
68 |
|
69 QPainter painter(this); |
|
70 style()->drawControl(QStyle::CE_PushButton, &option, &painter, this); |
|
71 } |
|
72 //! [0] |
|
73 |
|
74 |
|
75 |
|
76 class MyStyle : public QStyle |
|
77 { |
|
78 public: |
|
79 MyStyle(); |
|
80 |
|
81 void drawPrimitive(PrimitiveElement element, const QStyleOption *option, |
|
82 QPainter *painter, const QWidget *widget); |
|
83 }; |
|
84 |
|
85 MyStyle::MyStyle() |
|
86 { |
|
87 //! [1] |
|
88 QStyleOptionFrame *option; |
|
89 |
|
90 if (const QStyleOptionFrame *frameOption = |
|
91 qstyleoption_cast<const QStyleOptionFrame *>(option)) { |
|
92 QStyleOptionFrameV2 frameOptionV2(*frameOption); |
|
93 |
|
94 // draw the frame using frameOptionV2 |
|
95 } |
|
96 //! [1] |
|
97 |
|
98 //! [2] |
|
99 if (const QStyleOptionProgressBar *progressBarOption = |
|
100 qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { |
|
101 QStyleOptionProgressBarV2 progressBarV2(*progressBarOption); |
|
102 |
|
103 // draw the progress bar using progressBarV2 |
|
104 } |
|
105 //! [2] |
|
106 |
|
107 //! [3] |
|
108 if (const QStyleOptionTab *tabOption = |
|
109 qstyleoption_cast<const QStyleOptionTab *>(option)) { |
|
110 QStyleOptionTabV2 tabV2(*tabOption); |
|
111 |
|
112 // draw the tab using tabV2 |
|
113 } |
|
114 //! [3] |
|
115 } |
|
116 |
|
117 //! [4] |
|
118 void MyStyle::drawPrimitive(PrimitiveElement element, |
|
119 const QStyleOption *option, |
|
120 QPainter *painter, |
|
121 const QWidget *widget) |
|
122 { |
|
123 if (element == PE_FrameFocusRect) { |
|
124 const QStyleOptionFocusRect *focusRectOption = |
|
125 qstyleoption_cast<const QStyleOptionFocusRect *>(option); |
|
126 if (focusRectOption) { |
|
127 // ... |
|
128 } |
|
129 } |
|
130 // ... |
|
131 } |
|
132 //! [4] |
|
133 |
|
134 int main(int argc, char *argv[]) |
|
135 { |
|
136 QApplication app(argc, argv); |
|
137 MyPushButton button; |
|
138 button.show(); |
|
139 return app.exec(); |
|
140 } |