Jake
Jake

Reputation: 951

Vertical Spacer doesn't stretch past sizeHint in Form layout

I am trying to design a form in which some elements stay at the bottom of the Form Layout when the window size is increased, and others stay at the top. Using a Vertical Spacer between the top and bottom elements almost works, but the Vertical Spacer only stretches up to the Height value of its SizeHint (see screenshots below).

Simply increasing the SizeHint to some large has the unwanted side effect that the preferred size of the overall window then also becomes very large, so the "Adjust Size (Ctrl+J)" command makes the window unacceptably large.

If I use a Vertical Layout instead of a Form Layout, the stretcher behaves as I expect it to, increasing indefinitely and respecting the SizeHint when using "Adjust Size", but of course I lose the behaviour of the form layout (the alignment of the TextLabels).

What can I do to make the Vertical Spacer stretch past its SizeHint in a Form Layout?

Minimum size

Size increased

Upvotes: 1

Views: 3394

Answers (1)

MarPan
MarPan

Reputation: 113

Use multiple layouts, not only one.

  1. Set vertical layout for your window.
  2. Add horizontal layout, fill it with QLabel and QLineEdit. Add Vertical Spacer.
  3. Add another horizontal layout, fill it with QLabel and QLineEdit.
  4. Add horizontal layout, fill it with Vertical Spacer and two QPushButtons.

If I understood you correctly, you should get what you wanted :)

Another way is to use QGridLayout.

  1. Set QLabels to 0,0 and 1,0
  2. Set QPushButtons to 2,1 and 2,2
  3. Set QLineEdits to 0,1 and 1,1
  4. Drag QLineEdits so that they span from column 1 to column 2
  5. And Vertical Spacer between row 0 and 1.

Upvotes: 1

Related Questions