Thev00d00
Thev00d00

Reputation: 43

Set QBoxLayout maximum size?

I clearly missing something here, please enlighten me.

AttributeError: 'QVBoxLayout' object has no attribute 'setMaximumSize'

I've been reading the Qt Docs for a while but just cant seem to be able to get this to work

Upvotes: 2

Views: 11446

Answers (3)

Eli Bendersky
Eli Bendersky

Reputation: 273446

AFAIK you can't set a maximal size for a layout. Why would you want to - it makes no sense to me (which child widget should the layout limit?)

Regarding setMaximumSize - there's no such method for layouts. There is however, a QLayout::SetMaximumSize constraint which you can set, but this constraint applies to the widget that's laid out with this layout, not to the layout itself. It means that the widget can grow no larger than the maximal size of the layout - so this is quite different from what you need.

I recommend you re-think your real goal - perhaps it can be achieved in some other way. For instance, you can set the maximal size for the individual widgets laid out by your QBoxLayout.

Upvotes: 4

Brian Roach
Brian Roach

Reputation: 76898

Just as that error tells you, there is no setMaximumSize method on a layout.

QWidgets have that method.

Upvotes: 0

Judge Maygarden
Judge Maygarden

Reputation: 27583

You cannot set the maximumSize property directly as it is dynamically determined by the layout. Perhaps you are trying to set the QLayout.SizeConstraint to QLayout.SetMaximumSize? If so, then see the QLayout.setSizeConstraint method. Otherwise, you should call QWidget.setMaximumSize if you want to specify an exact maximum for a given widget.

Upvotes: 1

Related Questions