PyQt4 QHBoxLayout 单元格大小问题
PyQt4 QHBoxLayout cell size issue
我正在使用 PyQt4 QHBoxLayout 创建一个 window 与乘法框架,这是我的部分代码
def initUI(self):
hbox = QtGui.QHBoxLayout(self)
topleft = QtGui.QFrame(self)
topleft.setFrameShape(QtGui.QFrame.StyledPanel)
topright = QtGui.QFrame(self)
topright.setFrameShape(QtGui.QFrame.StyledPanel)
bottom = QtGui.QFrame(self)
bottom.setFrameShape(QtGui.QFrame.StyledPanel)
splitter1 = QtGui.QSplitter(QtCore.Qt.Horizontal)
splitter1.addWidget(topleft)
splitter1.addWidget(topright)
splitter2 = QtGui.QSplitter(QtCore.Qt.Vertical)
splitter2.addWidget(splitter1)
splitter2.addWidget(bottom)
hbox.addWidget(splitter2)
self.setLayout(hbox)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QtGui.QSplitter')
self.show()
但是输出好像连线了,因为toplift和topright框架被挤压了,我想知道有没有办法解决这个问题,让toplift和topright的高度与bottom的高度相同。
来自Qt Doc,QSplitter
有一个setSize
方法:
void QSplitter::setSizes(const QList<int> & list)
Sets the child widgets respective sizes to the values given in the
list.
If the splitter is horizontal, the values set the widths of each
widget in pixels, from left to right. If the splitter is vertical, the
heights of each widget is set, from top to bottom.
...
此外,对于任何 QWidget
,您可以使用 setMinimumSize
。
我正在使用 PyQt4 QHBoxLayout 创建一个 window 与乘法框架,这是我的部分代码
def initUI(self):
hbox = QtGui.QHBoxLayout(self)
topleft = QtGui.QFrame(self)
topleft.setFrameShape(QtGui.QFrame.StyledPanel)
topright = QtGui.QFrame(self)
topright.setFrameShape(QtGui.QFrame.StyledPanel)
bottom = QtGui.QFrame(self)
bottom.setFrameShape(QtGui.QFrame.StyledPanel)
splitter1 = QtGui.QSplitter(QtCore.Qt.Horizontal)
splitter1.addWidget(topleft)
splitter1.addWidget(topright)
splitter2 = QtGui.QSplitter(QtCore.Qt.Vertical)
splitter2.addWidget(splitter1)
splitter2.addWidget(bottom)
hbox.addWidget(splitter2)
self.setLayout(hbox)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QtGui.QSplitter')
self.show()
但是输出好像连线了,因为toplift和topright框架被挤压了,我想知道有没有办法解决这个问题,让toplift和topright的高度与bottom的高度相同。
来自Qt Doc,QSplitter
有一个setSize
方法:
void QSplitter::setSizes(const QList<int> & list)
Sets the child widgets respective sizes to the values given in the list.
If the splitter is horizontal, the values set the widths of each widget in pixels, from left to right. If the splitter is vertical, the heights of each widget is set, from top to bottom.
...
此外,对于任何 QWidget
,您可以使用 setMinimumSize
。