1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
#!/usr/bin/env python
#############################################################################
##
## Copyright (C) 2004-2005 Trolltech AS. All rights reserved.
##
## This file is part of the example classes of the Qt Toolkit.
##
## This file may be used under the terms of the GNU General Public
## License version 2.0 as published by the Free Software Foundation
## and appearing in the file LICENSE.GPL included in the packaging of
## this file. Please review the following information to ensure GNU
## General Public Licensing requirements will be met:
## http://www.trolltech.com/products/qt/opensource.html
##
## If you are unsure which license is appropriate for your use, please
## review the following information:
## http://www.trolltech.com/products/qt/licensing.html or contact the
## sales department at sales@trolltech.com.
##
## This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
##
#############################################################################
from PyQt4 import QtCore, QtGui
class WidgetGallery(QtGui.QDialog):
def __init__(self, parent=None):
super(WidgetGallery, self).__init__(parent)
self.originalPalette = QtGui.QApplication.palette()
styleComboBox = QtGui.QComboBox()
styleComboBox.addItems(QtGui.QStyleFactory.keys())
styleLabel = QtGui.QLabel("&Style:")
styleLabel.setBuddy(styleComboBox)
self.useStylePaletteCheckBox = QtGui.QCheckBox("&Use style's standard palette")
self.useStylePaletteCheckBox.setChecked(True)
disableWidgetsCheckBox = QtGui.QCheckBox("&Disable widgets")
self.createTopLeftGroupBox()
self.createTopRightGroupBox()
self.createBottomLeftTabWidget()
self.createBottomRightGroupBox()
self.createProgressBar()
styleComboBox.activated[str].connect(self.changeStyle)
self.useStylePaletteCheckBox.toggled.connect(self.changePalette)
disableWidgetsCheckBox.toggled.connect(self.topLeftGroupBox.setDisabled)
disableWidgetsCheckBox.toggled.connect(self.topRightGroupBox.setDisabled)
disableWidgetsCheckBox.toggled.connect(self.bottomLeftTabWidget.setDisabled)
disableWidgetsCheckBox.toggled.connect(self.bottomRightGroupBox.setDisabled)
topLayout = QtGui.QHBoxLayout()
topLayout.addWidget(styleLabel)
topLayout.addWidget(styleComboBox)
topLayout.addStretch(1)
topLayout.addWidget(self.useStylePaletteCheckBox)
topLayout.addWidget(disableWidgetsCheckBox)
mainLayout = QtGui.QGridLayout()
mainLayout.addLayout(topLayout, 0, 0, 1, 2)
mainLayout.addWidget(self.topLeftGroupBox, 1, 0)
mainLayout.addWidget(self.topRightGroupBox, 1, 1)
mainLayout.addWidget(self.bottomLeftTabWidget, 2, 0)
mainLayout.addWidget(self.bottomRightGroupBox, 2, 1)
mainLayout.addWidget(self.progressBar, 3, 0, 1, 2)
mainLayout.setRowStretch(1, 1)
mainLayout.setRowStretch(2, 1)
mainLayout.setColumnStretch(0, 1)
mainLayout.setColumnStretch(1, 1)
self.setLayout(mainLayout)
self.setWindowTitle("Styles")
self.changeStyle('Windows')
def changeStyle(self, styleName):
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create(styleName))
self.changePalette()
def changePalette(self):
if (self.useStylePaletteCheckBox.isChecked()):
QtGui.QApplication.setPalette(QtGui.QApplication.style().standardPalette())
else:
QtGui.QApplication.setPalette(self.originalPalette)
def advanceProgressBar(self):
curVal = self.progressBar.value()
maxVal = self.progressBar.maximum()
self.progressBar.setValue(curVal + (maxVal - curVal) / 100)
def createTopLeftGroupBox(self):
self.topLeftGroupBox = QtGui.QGroupBox("Group 1")
radioButton1 = QtGui.QRadioButton("Radio button 1")
radioButton2 = QtGui.QRadioButton("Radio button 2")
radioButton3 = QtGui.QRadioButton("Radio button 3")
radioButton1.setChecked(True)
checkBox = QtGui.QCheckBox("Tri-state check box")
checkBox.setTristate(True)
checkBox.setCheckState(QtCore.Qt.PartiallyChecked)
layout = QtGui.QVBoxLayout()
layout.addWidget(radioButton1)
layout.addWidget(radioButton2)
layout.addWidget(radioButton3)
layout.addWidget(checkBox)
layout.addStretch(1)
self.topLeftGroupBox.setLayout(layout)
def createTopRightGroupBox(self):
self.topRightGroupBox = QtGui.QGroupBox("Group 2")
defaultPushButton = QtGui.QPushButton("Default Push Button")
defaultPushButton.setDefault(True)
togglePushButton = QtGui.QPushButton("Toggle Push Button")
togglePushButton.setCheckable(True)
togglePushButton.setChecked(True)
flatPushButton = QtGui.QPushButton("Flat Push Button")
flatPushButton.setFlat(True)
layout = QtGui.QVBoxLayout()
layout.addWidget(defaultPushButton)
layout.addWidget(togglePushButton)
layout.addWidget(flatPushButton)
layout.addStretch(1)
self.topRightGroupBox.setLayout(layout)
def createBottomLeftTabWidget(self):
self.bottomLeftTabWidget = QtGui.QTabWidget()
self.bottomLeftTabWidget.setSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.Ignored)
tab1 = QtGui.QWidget()
tableWidget = QtGui.QTableWidget(10, 10)
tab1hbox = QtGui.QHBoxLayout()
tab1hbox.setMargin(5)
tab1hbox.addWidget(tableWidget)
tab1.setLayout(tab1hbox)
tab2 = QtGui.QWidget()
textEdit = QtGui.QTextEdit()
textEdit.setPlainText("Twinkle, twinkle, little star,\n"
"How I wonder what you are.\n"
"Up above the world so high,\n"
"Like a diamond in the sky.\n"
"Twinkle, twinkle, little star,\n"
"How I wonder what you are!\n")
tab2hbox = QtGui.QHBoxLayout()
tab2hbox.setMargin(5)
tab2hbox.addWidget(textEdit)
tab2.setLayout(tab2hbox)
self.bottomLeftTabWidget.addTab(tab1, "&Table")
self.bottomLeftTabWidget.addTab(tab2, "Text &Edit")
def createBottomRightGroupBox(self):
self.bottomRightGroupBox = QtGui.QGroupBox("Group 3")
self.bottomRightGroupBox.setCheckable(True)
self.bottomRightGroupBox.setChecked(True)
lineEdit = QtGui.QLineEdit('s3cRe7')
lineEdit.setEchoMode(QtGui.QLineEdit.Password)
spinBox = QtGui.QSpinBox(self.bottomRightGroupBox)
spinBox.setValue(50)
dateTimeEdit = QtGui.QDateTimeEdit(self.bottomRightGroupBox)
dateTimeEdit.setDateTime(QtCore.QDateTime.currentDateTime())
slider = QtGui.QSlider(QtCore.Qt.Horizontal, self.bottomRightGroupBox)
slider.setValue(40)
scrollBar = QtGui.QScrollBar(QtCore.Qt.Horizontal,
self.bottomRightGroupBox)
scrollBar.setValue(60)
dial = QtGui.QDial(self.bottomRightGroupBox)
dial.setValue(30)
dial.setNotchesVisible(True)
layout = QtGui.QGridLayout()
layout.addWidget(lineEdit, 0, 0, 1, 2)
layout.addWidget(spinBox, 1, 0, 1, 2)
layout.addWidget(dateTimeEdit, 2, 0, 1, 2)
layout.addWidget(slider, 3, 0)
layout.addWidget(scrollBar, 4, 0)
layout.addWidget(dial, 3, 1, 2, 1)
layout.setRowStretch(5, 1)
self.bottomRightGroupBox.setLayout(layout)
def createProgressBar(self):
self.progressBar = QtGui.QProgressBar()
self.progressBar.setRange(0, 10000)
self.progressBar.setValue(0)
timer = QtCore.QTimer(self)
timer.timeout.connect(self.advanceProgressBar)
timer.start(1000)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
gallery = WidgetGallery()
gallery.show()
sys.exit(app.exec_())
|