6
我試圖創建此geometery:QT網格佈局橫跨多個列
_ ___
| | |
|1| 3 |
|_|___|
|_2_|
凡1盒又高又瘦,2盒短而寬。我無法完全正確地確定佈局。當我將rowSpan和columnSpan從1到2從0變爲1時,我看到底部框的正確相對位置,但高度錯誤,框1的寬度錯誤。
這使QQ幫助,但並沒有完全解決我的問題:How to arrange the items in QGridLayout as shown?
import sys
from PyQt4 import QtGui
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
textEdit1 = QtGui.QTextEdit("LHS rectangle")
textEdit2 = QtGui.QTextEdit("Bottom rectangle")
textEdit3 = QtGui.QTextEdit("Central square")
self.gridLayout = QtGui.QGridLayout()
self.gridLayout.addWidget(textEdit1, 0, 0, 2, 0)
self.gridLayout.addWidget(textEdit2, 2, 1, 0, 2)
self.gridLayout.addWidget(textEdit3, 0, 1, 2, 2)
self.setLayout(self.gridLayout)
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
嘗試更換0按行跨度1,col span('textEdit1,0,0,2,1') – Mel
@tmoreau在我的機器上,它在textEdit3上方添加了少量textEdit2小部件,而不是在textEdit3下方。 –