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下方。 –