Qt Designer中網格布局中,layoutRowStretch和layoutColumnStretch兩個屬性分別設置網格布局中行之間和列之間的拉伸因子,如圖:
但是QGridLayout並沒有這兩個屬性,而從效果上說,這兩個屬性與rowStretch和columnStretch相似,只是rowStretch和columnStretch訪問或設置屬性時是要指定行或列的。語法如下:
1、columnStretch(int column)#獲取指定列的拉伸因子
2、rowStretch(int row) #獲取指定行的拉伸因子
3、setColumnStretch(int column, int stretch) #設置指定列的拉伸因子
4、setRowStretch(int row, int stretch) #設置指定行的拉伸因子
但Qt Designer中是一次設置多個值,我們來看看上述截圖生成的相關代碼,如下:
self.gridLayout.setColumnStretch(0, 1)
self.gridLayout.setColumnStretch(1, 1)
self.gridLayout.setColumnStretch(2, 4)
self.gridLayout.setRowStretch(0, 1)
self.gridLayout.setRowStretch(1, 1)
self.gridLayout.setRowStretch(2, 1)
self.gridLayout.setRowStretch(3, 1)
self.gridLayout.setRowStretch(4, 1)
self.gridLayout.setRowStretch(5, 1)
因此這是Designer中為了簡化界面設計而設置的這兩個屬性,實際上是映射到rowStretch和columnStretch。

博客地址:https://blog.csdn.net/LaoYuanPython
老猿Python博客文章目錄:https://blog.csdn.net/LaoYuanPython/article/details/98245036