How to make the bottom row of QGridLayout automatically fill the window's size in PyQt5?

时间:2017-12-18 06:50:21

标签: python qt user-interface pyqt pyqt5

As the window changes its size, I want to the bottom of the row, which is a QSplitter including 3 widgets, to expand and fill the remaining window while the widgets in the first row keep the original y-position. How to do that?

If the three widgets in QSplitter can keep their former ratio, it'll be better.

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        self.MainWindow=MainWindow
        self.MainWindow.setObjectName("self.MainWindow")

        self.MainWindow.resize(850, 800)
        self.centralwidget = QtWidgets.QWidget(self.MainWindow)
        self.MainWindow.setCentralWidget(self.centralwidget)

        self.vlayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setContentsMargins(0, 0, 0, 0)

        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setText("LABEL")
        self.comboBox = QtWidgets.QComboBox(self.centralwidget)        
        self.gridLayout.addWidget(self.label,0,0,1,1)
        self.gridLayout.addWidget(self.comboBox,0,1,1,9)

        """table """
        self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)

        """tab1"""
        self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
        self.tabWidget.setMinimumHeight(50)

        """tab2"""
        self.tabWidget_2 = QtWidgets.QTabWidget(self.centralwidget)
        self.tabWidget_2.setMinimumHeight(50)

        """splitter window"""     
        splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
        splitter.addWidget(self.tableWidget)
        splitter.addWidget(self.tabWidget)
        splitter.addWidget(self.tabWidget_2)
        splitter.setSizes([232,225,225])
        self.gridLayout.addWidget(splitter,3,0,5,10)
        self.gridLayout.setRowMinimumHeight(3,690)
        self.vlayout.addLayout(self.gridLayout)
        spacerItem = QtWidgets.QSpacerItem(20, 245, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        self.vlayout.addItem(spacerItem)

        QtCore.QMetaObject.connectSlotsByName(MainWindow)

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

enter image description here

enter image description here

I want to the QSplitter to expand to the bottom of the window.

0 个答案:

没有答案
相关问题