レイアウト - Box 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()

    okButton = QtGui.QPushButton("OK")
    cancelButton = QtGui.QPushButton("Cancel")

    hbox = QtGui.QHBoxLayout()
    hbox.addStretch(1)
    hbox.addWidget(okButton)
    hbox.addWidget(cancelButton)

    vbox = QtGui.QVBoxLayout()
    vbox.addStretch(1)
    vbox.addLayout(hbox)

    w.setLayout(vbox)

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

if __name__ == '__main__':
    main()


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