2011-12-18 47 views

回答

5

當然有。 QGridLayout在這種情況下可能會有用。

這裏是一個小例子:

import sys 
from PyQt4 import QtGui 

app = QtGui.QApplication(sys.argv) 
widget = QtGui.QWidget() 
layout = QtGui.QGridLayout() 

buttons = {} 

for i in range(10): 
    for j in range(10): 
     # keep a reference to the buttons 
     buttons[(i, j)] = QtGui.QPushButton('row %d, col %d' % (i, j)) 
     # add to the layout 
     layout.addWidget(buttons[(i, j)], i, j) 

widget.setLayout(layout) 
widget.show() 
sys.exit(app.exec_()) 

結果:

QGridLayout