1#!/usr/bin/env python 2############################################################################# 3## 4## Copyright (C) 2015 The Qt Company Ltd. 5## Contact: http://www.qt.io/licensing/ 6## 7## This file is part of the documentation of the Qt Toolkit. 8## 9## $QT_BEGIN_LICENSE:LGPL$ 10## Commercial License Usage 11## Licensees holding valid commercial Qt licenses may use this file in 12## accordance with the commercial license agreement provided with the 13## Software or, alternatively, in accordance with the terms contained in 14## a written agreement between you and The Qt Company. For licensing terms 15## and conditions see http://www.qt.io/terms-conditions. For further 16## information use the contact form at http://www.qt.io/contact-us. 17## 18## GNU Lesser General Public License Usage 19## Alternatively, this file may be used under the terms of the GNU Lesser 20## General Public License version 2.1 or version 3 as published by the Free 21## Software Foundation and appearing in the file LICENSE.LGPLv21 and 22## LICENSE.LGPLv3 included in the packaging of this file. Please review the 23## following information to ensure the GNU Lesser General Public License 24## requirements will be met: https://www.gnu.org/licenses/lgpl.html and 25## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 26## 27## As a special exception, The Qt Company gives you certain additional 28## rights. These rights are described in The Qt Company LGPL Exception 29## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 30## 31## GNU General Public License Usage 32## Alternatively, this file may be used under the terms of the GNU 33## General Public License version 3.0 as published by the Free Software 34## Foundation and appearing in the file LICENSE.GPL included in the 35## packaging of this file. Please review the following information to 36## ensure the GNU General Public License version 3.0 requirements will be 37## met: http://www.gnu.org/copyleft/gpl.html. 38## 39## $QT_END_LICENSE$ 40## 41############################################################################# 42 43import os, sys 44from PyQt4.QtCore import * 45from PyQt4.QtGui import * 46 47 48def 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 78class 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 97if __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_()) 185