Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt - Horizontal spacer

Tags:

c++

qt

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.

like image 863
Simplicity Avatar asked Apr 11 '11 07:04

Simplicity


People also ask

How do I add a horizontal spacer in Qt?

You can add a spacer item, either on the outside of your horizontal layout, or inside your horizontal layout. If you add the spacer item inside the horizontal layout, you have to make sure you add your label widgets before the spacer item. Use the insertWidget() function to add your labels in this case.

What are buddies in Qt?

In Qt, buddies are connections between related widgets. Normally between a QLabel widget and an input widget like a QLineEdit or a QComboBox . These connections allow you to provide a quick keyboard shortcut to move the focus to a given input widget.

What is QVBoxLayout?

QVBoxLayout organizes your widgets vertically in a window. Instead of organizing all the widgets yourself (specifying the geographic location), you can let PyQt take care of it. Every new widget you add with . addWidget() , is added vertically. Basically you get a vertical list of your widgets.


1 Answers

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]
like image 112
Patrick Avatar answered Sep 20 '22 16:09

Patrick