0
|
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 |
class CustomWidget(QWidget):
|
|
48 |
|
|
49 |
def __init__(self, parent, fake = False):
|
|
50 |
|
|
51 |
QWidget.__init__(self, parent)
|
|
52 |
gradient = QLinearGradient(QPointF(0, 0), QPointF(100.0, 100.0))
|
|
53 |
baseColor = QColor(0xa6, 0xce, 0x39, 0x7f)
|
|
54 |
gradient.setColorAt(0.0, baseColor.light(150))
|
|
55 |
gradient.setColorAt(0.75, baseColor.light(75))
|
|
56 |
self.brush = QBrush(gradient)
|
|
57 |
self.fake = fake
|
|
58 |
self.fakeBrush = QBrush(Qt.red, Qt.DiagCrossPattern)
|
|
59 |
|
|
60 |
qtPath = QPainterPath()
|
|
61 |
qtPath.setFillRule(Qt.OddEvenFill)
|
|
62 |
qtPath.moveTo(-45.0, -20.0)
|
|
63 |
qtPath.lineTo(0.0, -45.0)
|
|
64 |
qtPath.lineTo(45.0, -20.0)
|
|
65 |
qtPath.lineTo(45.0, 45.0)
|
|
66 |
qtPath.lineTo(-45.0, 45.0)
|
|
67 |
qtPath.lineTo(-45.0, -20.0)
|
|
68 |
qtPath.closeSubpath()
|
|
69 |
qtPath.moveTo(15.0, 5.0)
|
|
70 |
qtPath.lineTo(35.0, 5.0)
|
|
71 |
qtPath.lineTo(35.0, 40.0)
|
|
72 |
qtPath.lineTo(15.0, 40.0)
|
|
73 |
qtPath.lineTo(15.0, 5.0)
|
|
74 |
qtPath.moveTo(-35.0, -15.0)
|
|
75 |
qtPath.closeSubpath()
|
|
76 |
qtPath.lineTo(-10.0, -15.0)
|
|
77 |
qtPath.lineTo(-10.0, 10.0)
|
|
78 |
qtPath.lineTo(-35.0, 10.0)
|
|
79 |
qtPath.lineTo(-35.0, -15.0)
|
|
80 |
qtPath.closeSubpath()
|
|
81 |
self.path = qtPath
|
|
82 |
|
|
83 |
def paintEvent(self, event):
|
|
84 |
|
|
85 |
painter = QPainter()
|
|
86 |
painter.begin(self)
|
|
87 |
painter.setRenderHint(QPainter.Antialiasing)
|
|
88 |
if self.fake:
|
|
89 |
painter.fillRect(event.rect(), QBrush(Qt.white))
|
|
90 |
painter.fillRect(event.rect(), self.fakeBrush)
|
|
91 |
painter.setBrush(self.brush)
|
|
92 |
painter.translate(60, 60)
|
|
93 |
painter.drawPath(self.path)
|
|
94 |
painter.end()
|
|
95 |
|
|
96 |
def sizeHint(self):
|
|
97 |
|
|
98 |
return QSize(120, 120)
|
|
99 |
|
|
100 |
def minimumSizeHint(self):
|
|
101 |
|
|
102 |
return QSize(120, 120)
|
|
103 |
|
|
104 |
|
|
105 |
if __name__ == "__main__":
|
|
106 |
|
|
107 |
try:
|
|
108 |
qt = sys.argv[1]
|
|
109 |
except IndexError:
|
|
110 |
qt = "4.1"
|
|
111 |
|
|
112 |
if qt != "4.0" and qt != "4.1":
|
|
113 |
sys.stderr.write("Usage: %s [4.0|4.1]\n" % sys.argv[0])
|
|
114 |
sys.exit(1)
|
|
115 |
|
|
116 |
app = QApplication(sys.argv)
|
|
117 |
exec_dir = os.path.split(os.path.abspath(sys.argv[0]))[0]
|
|
118 |
label = QLabel()
|
|
119 |
label.setPixmap(QPixmap(os.path.join(exec_dir, "background.png")))
|
|
120 |
|
|
121 |
layout = QGridLayout()
|
|
122 |
label.setLayout(layout)
|
|
123 |
if qt == "4.0":
|
|
124 |
layout.addWidget(CustomWidget(label), 0, 0, Qt.AlignCenter)
|
|
125 |
caption = QLabel("Opaque (Default)", label)
|
|
126 |
caption.setMargin(2)
|
|
127 |
layout.addWidget(caption, 1, 0, Qt.AlignCenter | Qt.AlignTop)
|
|
128 |
elif qt == "4.1":
|
|
129 |
layout.addWidget(CustomWidget(label), 0, 0, Qt.AlignCenter)
|
|
130 |
caption = QLabel("Contents Propagated (Default)", label)
|
|
131 |
caption.setAutoFillBackground(True)
|
|
132 |
caption.setMargin(2)
|
|
133 |
layout.addWidget(caption, 1, 0, Qt.AlignCenter | Qt.AlignTop)
|
|
134 |
|
|
135 |
if qt == "4.0":
|
|
136 |
contentsWidget = CustomWidget(label)
|
|
137 |
contentsWidget.setAttribute(Qt.WA_ContentsPropagated, True)
|
|
138 |
layout.addWidget(contentsWidget, 0, 1, Qt.AlignCenter)
|
|
139 |
caption = QLabel("With WA_ContentsPropagated set", label)
|
|
140 |
caption.setMargin(2)
|
|
141 |
layout.addWidget(caption, 1, 1, Qt.AlignCenter | Qt.AlignTop)
|
|
142 |
elif qt == "4.1":
|
|
143 |
autoFillWidget = CustomWidget(label)
|
|
144 |
autoFillWidget.setAutoFillBackground(True)
|
|
145 |
layout.addWidget(autoFillWidget, 0, 1, Qt.AlignCenter)
|
|
146 |
caption = QLabel("With autoFillBackground set", label)
|
|
147 |
caption.setAutoFillBackground(True)
|
|
148 |
caption.setMargin(2)
|
|
149 |
layout.addWidget(caption, 1, 1, Qt.AlignCenter | Qt.AlignTop)
|
|
150 |
|
|
151 |
if qt == "4.0":
|
|
152 |
noBackgroundWidget = CustomWidget(label, fake = True)
|
|
153 |
noBackgroundWidget.setAttribute(Qt.WA_NoBackground, True)
|
|
154 |
layout.addWidget(noBackgroundWidget, 0, 2, Qt.AlignCenter)
|
|
155 |
caption = QLabel("With WA_NoBackground set", label)
|
|
156 |
caption.setWordWrap(True)
|
|
157 |
caption.setMargin(2)
|
|
158 |
layout.addWidget(caption, 1, 2, Qt.AlignCenter | Qt.AlignTop)
|
|
159 |
elif qt == "4.1":
|
|
160 |
opaqueWidget = CustomWidget(label, fake = True)
|
|
161 |
opaqueWidget.setAttribute(Qt.WA_OpaquePaintEvent, True)
|
|
162 |
layout.addWidget(opaqueWidget, 0, 2, Qt.AlignCenter)
|
|
163 |
caption = QLabel("With WA_OpaquePaintEvent set", label)
|
|
164 |
caption.setAutoFillBackground(True)
|
|
165 |
caption.setMargin(2)
|
|
166 |
layout.addWidget(caption, 1, 2, Qt.AlignCenter | Qt.AlignTop)
|
|
167 |
|
|
168 |
if qt == "4.0":
|
|
169 |
label.setWindowTitle("Qt 4.0: Painting Custom Widgets")
|
|
170 |
elif qt == "4.1":
|
|
171 |
label.setWindowTitle("Qt 4.1: Painting Custom Widgets")
|
|
172 |
|
|
173 |
label.resize(404, 160)
|
|
174 |
label.show()
|
|
175 |
sys.exit(app.exec_())
|