from PyQt4 import QtCore, QtGui
class WidgetGallery(QtGui.QDialog):
def __init__(self,parent=None):
super(WidgetGallery,self).
__init__(parent)

self.palette
= QtGui.QApplication.palette()


combo_box
= QtGui.QComboBox()
combo_box.addItems(QtGui.QStyleFactory.keys())

label
= QtGui.QLabel('style')
label.setBuddy(combo_box)

check_box_one
= QtGui.QCheckBox('use')
check_box_one.setChecked(True)

check_box_two
= QtGui.QCheckBox('disable')

self.createTopLeftGroupBox()
self.createTopRightGroupBox()
self.createBottomLeftTabWidget()
self.createBottomRightGroupBox()
self.createProgressBar()

combo_box.activated[str].connect(self.changeStyle)
check_box_one.toggled.connect(self.changePalette)
check_box_two.toggled.connect(self.topLeftGroupBox.setDisabled)
check_box_two.toggled.connect(self.topRightGroupBox.setDisabled)
check_box_two.toggled.connect(self.bottomLeftTabWidget.setDisabled)
check_box_two.toggled.connect(self.bottomRightGroupBox.setDisabled)

layout_x
= QtGui.QHBoxLayout()
layout_x.addWidget(label)
layout_x.addWidget(combo_box)
layout_x.addStretch(
1)
layout_x.addWidget(check_box_one)
layout_x.addWidget(check_box_two)

mainLayout
= QtGui.QGridLayout()
mainLayout.addLayout(layout_x, 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.progress_bar,
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(
'style')
#self.resize(100,100)

def changeStyle(self,styleName):
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create(styleName))
self.changePalette()

def changePalette(self):
if (check_box_one.isChecked()):
QtGui.QApplication.setPalette(QtGui.QApplication.style().standardPalette())
else:
QtGui.QApplication.setPalette(self.originalPalette)

def advanceProgressBar(self):
curval
= self.progress_bar.value()
maxval
= self.progress_bar.maximum()
self.progress_bar.setValue(curval
+(maxval-curval)/100)



def createTopLeftGroupBox(self):
self.topLeftGroupBox
= QtGui.QGroupBox('group_one')

button1
= QtGui.QRadioButton('radio_button_a')
button2
= QtGui.QRadioButton('radio_button_a')
button3
= QtGui.QRadioButton('radio_button_a')
button1.setChecked(True)

layout
= QtGui.QVBoxLayout()
layout.addWidget(button1)
layout.addWidget(button2)
layout.addWidget(button3)

self.topLeftGroupBox.setLayout(layout)

def createTopRightGroupBox(self):
self.topRightGroupBox
= QtGui.QGroupBox('group_two')
def createBottomLeftTabWidget(self):
self.bottomLeftTabWidget
= QtGui.QTabWidget()
tab1
= QtGui.QWidget()
table1
= QtGui.QTableWidget(5,5)

tab1_layout
= QtGui.QHBoxLayout()
tab1_layout.setMargin(
5)
tab1_layout.addWidget(table1)
tab1.setLayout(tab1_layout)

tab2
= QtGui.QWidget()
table2
= QtGui.QTextEdit()
table2.setPlainText(
'hello world')

tab2_layout
= QtGui.QHBoxLayout()
tab2_layout.setMargin(
5)
tab2_layout.addWidget(table2)
tab2.setLayout(tab2_layout)

self.bottomLeftTabWidget.addTab(tab1,
'table widget')
self.bottomLeftTabWidget.addTab(tab2,
'text widget')


def createBottomRightGroupBox(self):
self.bottomRightGroupBox
= QtGui.QGroupBox('group_three')
def createProgressBar(self):
self.progress_bar
= QtGui.QProgressBar()
self.progress_bar.setRange(0,
10000)
self.progress_bar.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_())

 posted on 2011-07-10 13:55  eth0  阅读(508)  评论(0编辑  收藏  举报