网格布局-跨行跨列

import sys
from PyQt4 import QtCore, QtGui

class MainWindow(QtGui.QWidget):
    
    def __init__(self, parent = None):
        QtGui.QWidget.__init__(self)
        self.setWindowTitle('grid layout')
        
        title = QtGui.QLabel('Title')
        authot = QtGui.QLabel('Author')
        review = QtGui.QLabel('Review')
        
        titleEdit = QtGui.QLineEdit()
        authorEdit = QtGui.QLineEdit()
        reviewEdit = QtGui.QLineEdit()
        
        # 创建了一个网格布局,并将布局中的部件间隔(同行的横向间隔)设为10个字距
        grid = QtGui.QGridLayout()
        grid.setSpacing(10)
        
        grid.addWidget(title, 1, 0)
        grid.addWidget(titleEdit, 1, 1)
        
        grid.addWidget(authot, 2, 0)
        grid.addWidget(authorEdit, 2, 1)
        
        grid.addWidget(review, 3, 0)
        grid.addWidget(reviewEdit, 3, 1, 5, 1) # 为加入的网格布局中的部件设置行列跨度。行跨度设置为5,列跨度设置为1
        
        self.setLayout(grid)
        self.resize(350, 300)       
           
        
app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())

posted @ 2017-07-19 17:24  蒋励  阅读(1088)  评论(0编辑  收藏  举报