Python 如何使QHBoxLayout具有固定比率?

Python 如何使QHBoxLayout具有固定比率?,python,qt,layout,pyside2,Python,Qt,Layout,Pyside2,正如下图所示,我有一个QHBoxLayout。在这个2QVBOxLayout中,我向这两者添加了一系列小部件。但我希望QHBX版图的分割在中间是完美的。每一面内部的一些小部件都有扩展选项,但我不希望QHBoxLayout允许任何一面跨越整个窗口一半以上的大小 这可能吗?我该怎么做 一种可能的解决方案是在添加QVBoxLayout时设置相同的拉伸系数: from PyQt5 import QtCore, QtGui, QtWidgets class Widget(QtWidgets.QWidg

正如下图所示,我有一个QHBoxLayout。在这个2QVBOxLayout中,我向这两者添加了一系列小部件。但我希望QHBX版图的分割在中间是完美的。每一面内部的一些小部件都有扩展选项,但我不希望QHBoxLayout允许任何一面跨越整个窗口一半以上的大小

这可能吗?我该怎么做


一种可能的解决方案是在添加QVBoxLayout时设置相同的拉伸系数:

from PyQt5 import QtCore, QtGui, QtWidgets


class Widget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)

        hlay = QtWidgets.QHBoxLayout(self)

        left_vlay = QtWidgets.QVBoxLayout()
        right_vlay = QtWidgets.QVBoxLayout()

        hlay.addLayout(left_vlay, stretch=1)
        hlay.addLayout(right_vlay, stretch=1)

        left_vlay.addWidget(QtWidgets.QTextEdit())
        right_vlay.addWidget(QtWidgets.QLineEdit())

if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)
    w = Widget()
    w.show()
    sys.exit(app.exec_())