|
1 #!/usr/bin/env python |
|
2 ############################################################################# |
|
3 ## |
|
4 ## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
5 ## All rights reserved. |
|
6 ## Contact: Nokia Corporation (qt-info@nokia.com) |
|
7 ## |
|
8 ## This file is part of the test suite of the Qt Toolkit. |
|
9 ## |
|
10 ## $QT_BEGIN_LICENSE:LGPL$ |
|
11 ## No Commercial Usage |
|
12 ## This file contains pre-release code and may not be distributed. |
|
13 ## You may use this file in accordance with the terms and conditions |
|
14 ## contained in the Technology Preview License Agreement accompanying |
|
15 ## this package. |
|
16 ## |
|
17 ## GNU Lesser General Public License Usage |
|
18 ## Alternatively, this file may be used under the terms of the GNU Lesser |
|
19 ## General Public License version 2.1 as published by the Free Software |
|
20 ## Foundation and appearing in the file LICENSE.LGPL included in the |
|
21 ## packaging of this file. Please review the following information to |
|
22 ## ensure the GNU Lesser General Public License version 2.1 requirements |
|
23 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
24 ## |
|
25 ## In addition, as a special exception, Nokia gives you certain additional |
|
26 ## rights. These rights are described in the Nokia Qt LGPL Exception |
|
27 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
28 ## |
|
29 ## If you have questions regarding the use of this file, please contact |
|
30 ## Nokia at qt-info@nokia.com. |
|
31 ## |
|
32 ## |
|
33 ## |
|
34 ## |
|
35 ## |
|
36 ## |
|
37 ## |
|
38 ## |
|
39 ## $QT_END_LICENSE$ |
|
40 ## |
|
41 ############################################################################# |
|
42 |
|
43 import os, sys |
|
44 from PyQt4.QtCore import * |
|
45 from PyQt4.QtGui import * |
|
46 |
|
47 |
|
48 def createGroupBox(parent, attributes = None, fill = False, fake = False): |
|
49 |
|
50 background = CustomWidget(parent, fake) |
|
51 backgroundLayout = QVBoxLayout() |
|
52 backgroundLayout.setMargin(4) |
|
53 background.setLayout(backgroundLayout) |
|
54 |
|
55 groupBox = QGroupBox("&Options") |
|
56 layout = QGridLayout() |
|
57 groupBox.setLayout(layout) |
|
58 layout.addWidget(QCheckBox("C&ase sensitive"), 0, 0) |
|
59 layout.addWidget(QCheckBox("W&hole words"), 0, 1) |
|
60 checkedBox = QCheckBox("Search &forwards") |
|
61 checkedBox.setChecked(True) |
|
62 layout.addWidget(checkedBox, 1, 0) |
|
63 layout.addWidget(QCheckBox("From &start of text"), 1, 1) |
|
64 |
|
65 backgroundLayout.addWidget(groupBox) |
|
66 |
|
67 if attributes: |
|
68 for attr in attributes: |
|
69 groupBox.setAttribute(attr, True) |
|
70 if not fake: |
|
71 background.setAttribute(attr, True) |
|
72 |
|
73 groupBox.setAutoFillBackground(fill) |
|
74 background.setAutoFillBackground(fill) |
|
75 |
|
76 return background |
|
77 |
|
78 class CustomWidget(QWidget): |
|
79 |
|
80 def __init__(self, parent, fake = False): |
|
81 |
|
82 QWidget.__init__(self, parent) |
|
83 self.fake = fake |
|
84 self.fakeBrush = QBrush(Qt.red, Qt.DiagCrossPattern) |
|
85 |
|
86 def paintEvent(self, event): |
|
87 |
|
88 painter = QPainter() |
|
89 painter.begin(self) |
|
90 painter.setRenderHint(QPainter.Antialiasing) |
|
91 if self.fake: |
|
92 painter.fillRect(event.rect(), QBrush(Qt.white)) |
|
93 painter.fillRect(event.rect(), self.fakeBrush) |
|
94 painter.end() |
|
95 |
|
96 |
|
97 if __name__ == "__main__": |
|
98 |
|
99 try: |
|
100 qt = sys.argv[1] |
|
101 except IndexError: |
|
102 qt = "4.1" |
|
103 |
|
104 if qt != "4.0" and qt != "4.1": |
|
105 sys.stderr.write("Usage: %s [4.0|4.1]\n" % sys.argv[0]) |
|
106 sys.exit(1) |
|
107 |
|
108 app = QApplication(sys.argv) |
|
109 exec_dir = os.path.split(os.path.abspath(sys.argv[0]))[0] |
|
110 label = QLabel() |
|
111 label.setPixmap(QPixmap(os.path.join(exec_dir, "lightbackground.png"))) |
|
112 |
|
113 layout = QGridLayout() |
|
114 label.setLayout(layout) |
|
115 if qt == "4.0": |
|
116 layout.addWidget(createGroupBox(label), 0, 0, Qt.AlignCenter) |
|
117 caption = QLabel("Opaque (Default)", label) |
|
118 caption.setMargin(2) |
|
119 layout.addWidget(caption, 1, 0, Qt.AlignCenter | Qt.AlignTop) |
|
120 elif qt == "4.1": |
|
121 layout.addWidget(createGroupBox(label), 0, 0, Qt.AlignCenter) |
|
122 caption = QLabel("Contents Propagated (Default)", label) |
|
123 caption.setAutoFillBackground(True) |
|
124 caption.setMargin(2) |
|
125 layout.addWidget(caption, 1, 0, Qt.AlignCenter | Qt.AlignTop) |
|
126 |
|
127 if qt == "4.0": |
|
128 contentsWidget = createGroupBox(label) |
|
129 contentsWidget.setAttribute(Qt.WA_ContentsPropagated, True) |
|
130 layout.addWidget(contentsWidget, 0, 1, Qt.AlignCenter) |
|
131 caption = QLabel("With WA_ContentsPropagated set", label) |
|
132 caption.setMargin(2) |
|
133 layout.addWidget(caption, 1, 1, Qt.AlignCenter | Qt.AlignTop) |
|
134 elif qt == "4.1": |
|
135 autoFillWidget = createGroupBox(label, fill = True) |
|
136 layout.addWidget(autoFillWidget, 0, 1, Qt.AlignCenter) |
|
137 caption = QLabel("With autoFillBackground set", label) |
|
138 caption.setAutoFillBackground(True) |
|
139 caption.setMargin(2) |
|
140 layout.addWidget(caption, 1, 1, Qt.AlignCenter | Qt.AlignTop) |
|
141 |
|
142 # if qt == "4.0": |
|
143 # noBackgroundWidget = createGroupBox( |
|
144 # label, attributes = [Qt.WA_NoBackground], fake = True) |
|
145 # layout.addWidget(noBackgroundWidget, 2, 0, Qt.AlignCenter) |
|
146 # caption = QLabel("With WA_NoBackground set", label) |
|
147 # caption.setWordWrap(True) |
|
148 # caption.setMargin(2) |
|
149 # layout.addWidget(caption, 3, 0, Qt.AlignCenter | Qt.AlignTop) |
|
150 # elif qt == "4.1": |
|
151 # opaqueWidget = createGroupBox( |
|
152 # label, attributes = [Qt.WA_OpaquePaintEvent], fake = True) |
|
153 # layout.addWidget(opaqueWidget, 2, 0, Qt.AlignCenter) |
|
154 # caption = QLabel("With WA_OpaquePaintEvent set", label) |
|
155 # caption.setAutoFillBackground(True) |
|
156 # caption.setMargin(2) |
|
157 # layout.addWidget(caption, 3, 0, Qt.AlignCenter | Qt.AlignTop) |
|
158 # |
|
159 # if qt == "4.0": |
|
160 # contentsNoBackgroundWidget = createGroupBox( |
|
161 # label, attributes = [Qt.WA_ContentsPropagated, Qt.WA_NoBackground], |
|
162 # fake = True) |
|
163 # layout.addWidget(contentsNoBackgroundWidget, 2, 1, Qt.AlignCenter) |
|
164 # caption = QLabel("With WA_ContentsPropagated and WA_NoBackground set", label) |
|
165 # caption.setMargin(2) |
|
166 # layout.addWidget(caption, 3, 1, Qt.AlignCenter | Qt.AlignTop) |
|
167 # elif qt == "4.1": |
|
168 # opaqueAutoFillWidget = createGroupBox( |
|
169 # label, attributes = [Qt.WA_OpaquePaintEvent], fill = True, fake = True) |
|
170 # layout.addWidget(opaqueAutoFillWidget, 2, 1, Qt.AlignCenter) |
|
171 # caption = QLabel("With WA_OpaquePaintEvent and autoFillBackground set", label) |
|
172 # caption.setWordWrap(True) |
|
173 # caption.setAutoFillBackground(True) |
|
174 # caption.setMargin(2) |
|
175 # layout.addWidget(caption, 3, 1, Qt.AlignCenter | Qt.AlignTop) |
|
176 |
|
177 if qt == "4.0": |
|
178 label.setWindowTitle("Qt 4.0: Painting Standard Qt Widgets") |
|
179 elif qt == "4.1": |
|
180 label.setWindowTitle("Qt 4.1: Painting Standard Qt Widgets") |
|
181 |
|
182 label.resize(480, 140) |
|
183 label.show() |
|
184 sys.exit(app.exec_()) |