Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt: Unequally divide the area occupied by widgets in a QHBoxLayout

I want to have a layout like the following:

Layout

I am using a QHBoxLayout and adding two widgets - but instead of the 25% / 75% layout that I require, both the widgets get 50% of the available space.

How do I distribute the area for the widgets unequally?

like image 358
Sarah Avatar asked Jan 23 '26 23:01

Sarah


1 Answers

The QHBoxLayout and QVBoxLayout classes allow you to set a stretch factor when adding widgets. This specifies the relative proportion of space taken up by the widget, after the widget's minimum/maximum width/height has been taken into account:

layout = QHBoxLayout()
layout.addWidget(widget1, 25)
layout.addWidget(widget2, 75)
like image 53
ekhumoro Avatar answered Jan 26 '26 12:01

ekhumoro