レイアウト - Grid Layout

2014/12/13

Python2.7.6, pyQt4.11

# -*- coding: utf-8 -*-

import sys
from PyQt4 import QtGui

def main():

    app = QtGui.QApplication(sys.argv)
    w = QtGui.QWidget()

    btn1 = QtGui.QPushButton("1")
    btn2 = QtGui.QPushButton("2")
    btn3 = QtGui.QPushButton("3")
    btn4 = QtGui.QPushButton("4")

    grid = QtGui.QGridLayout()
    grid.addWidget(btn1,0,0)
    grid.addWidget(btn2,0,1)
    grid.addWidget(btn3,1,0)
    grid.addWidget(btn4,1,1)

    w.setLayout(grid)

    w.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()


参考
Layout management in PyQt4
http://zetcode.com/gui/pyqt4/layoutmanagement/