Sarah
Sarah

Reputation: 161

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?

Upvotes: 3

Views: 2555

Answers (1)

ekhumoro
ekhumoro

Reputation: 120718

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)

Upvotes: 6

Related Questions