Simplicity
Simplicity

Reputation: 48916

Qt - Horizontal spacer

I want to ask about the horizontal spacer in Qt.

I couldn't get its effect when adding it to the form for example through the Qt designer.

Why do we use the horizontal spacer? What is its purpose?

Thanks.

Upvotes: 7

Views: 10406

Answers (1)

Patrick
Patrick

Reputation: 23619

It's used to prevent widgets from stretching or moving across the window.

Suppose you have a window a with a horizontal layout and the following widgets besides each other:

[LABEL EDIT]

If you resize the window, the widgets will be stretched with the window. In this case, the edit widget will probably be stretched, and you get this:

[LABEL E   D   I   T]

You can make the edit widget fixed, but then you get this after a resize

[LABEL          EDIT        ]

To keep the edit control on its place, use a horizontal spacer:

[LABEL EDIT SPACER]

If the window is now resized, you will get this:

[LABEL EDIT S  P  A  C  E  R]

Upvotes: 27

Related Questions