Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set widget in center in QDesigner

Is it possible to set widget in center of dialog or windows in QDesigner, say I have a widget contain 3 line edits and labels and I want to set this widget in center of window.

like image 285
SIFE Avatar asked Mar 22 '11 13:03

SIFE


People also ask

How do I align widgets in Qt?

Right-click the relevant widget and select Layout alignment > Top. (NB: the new alignment will only be shown in preview mode).

How do you center text in Qlabel?

What you need to do is align the text inside the label, not the label itself i.e. m_TextLabel->setAlignment(Qt::AlignCenter) .

How do I add widgets to the main window in Qt?

For QHBoxLayout or QVBoxLayout you can call addWidget() to put it on the end, or insertWidget() to put it in the middle somewhere. This is pretty much the same thing that happens when you call setupUi() in your main window constructor, where Qt reads the compiled ui description and instantiates the widgets to build it.

How do I resize a layout in Qt?

Once you have add your layout with at least one widget in it, select your window and click the "Update" button of QtDesigner. The interface will be resized at the most optimized size and your layout will fit the whole window. Then when resizing the window, the layout will be resized in the same way.


2 Answers

In latest Qt Designer, right-click a widget in the Object Inspector and choose your preference under Layout Alignment.

Layout Alignment

like image 102
AndiDog Avatar answered Sep 18 '22 10:09

AndiDog


It should be quite simple:

  1. Insert horizontal spacer
  2. Set Horizontal layout
  3. Insert Vertical layout
  4. Insert another horizontal spacer

  5. Add Vertical spacer to Horizontal spacer (drag to widget tree)

  6. Add your widgets .... labels, textedits
  7. Add another vertical sapcer to Horizontal space

Works in my QtCreator, should also in Your Designer :)

Good luck.

like image 28
Sebastian Dusza Avatar answered Sep 20 '22 10:09

Sebastian Dusza