Search code examples
pythonpython-3.xpyqtpyqt5qwidget

How to use QGridLayout to incorporate proportional sizes?


Here's the code I'm using to layout the widgets on my window :

    widget = QWidget()
    self.setCentralWidget(widget)

    layout = QGridLayout()

    map_group_box = QGroupBox()
    map_group_box.setTitle('Navigation')

    panel_group_box = QGroupBox()
    panel_group_box.setTitle('Instrument Panel')

    status_group_box = QGroupBox()
    status_group_box.setTitle('Status')

    layout.addWidget(map_group_box, 0, 0, 2, 1)
    layout.addWidget(panel_group_box, 0, 1, 1, 1)
    layout.addWidget(status_group_box, 1, 1, 1, 1)

    widget.setLayout(layout)

This is the result :

Result 1

I would like the left column to be twice as wide as the ones on the left. How do I achieve that ? I have tried QSplitters, but they look so damn ugly on macOS.


Solution

  • after adding the widgets to layout:

    layout.setColumnStretch(0, 2)
    layout.setColumnStretch(1, 1)