PySide: 简单窗体布局

演示简单的窗体布局以及通过Signal/Slot同步QSlider和QSpinBox。

演示程序使用了三个Widget(不知道应该译成组件、控件还是部件,就直接用Widget吧):QSlider、QSpinBox和QWidget。QWidget作为程序的主窗体,并作为QSlider和QSpinbox的父容器。

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from PySide.QtCore import *
from PySide.QtGui import *

app = QApplication(sys.argv)

window = QWidget()
window.setWindowTitle('Enter Your Age')

spinBox = QSpinBox()
spinBox.setRange(0, 130)

slider = QSlider(Qt.Horizontal)
slider.setRange(0, 130)

QObject.connect(spinBox, SIGNAL('valueChanged(int)'),
            slider, SLOT('setValue(int)'))
QObject.connect(slider, SIGNAL('valueChanged(int)'),
            spinBox, SLOT('setValue(int)'))
spinBox.setValue(35)

button = QPushButton('Quit')
QObject.connect(button, SIGNAL('clicked()'),
                window, SLOT('close()'))

layout = QHBoxLayout()
layout.addWidget(spinBox)
layout.addWidget(slider)
layout.addWidget(button)

window.setLayout(layout)

window.show()

sys.exit(app.exec_())

 

posted @ 2010-10-26 02:13  Sean Lv  阅读(...)  评论(...编辑  收藏