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.
Right-click the relevant widget and select Layout alignment > Top. (NB: the new alignment will only be shown in preview mode).
What you need to do is align the text inside the label, not the label itself i.e. m_TextLabel->setAlignment(Qt::AlignCenter) .
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.
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.
In latest Qt Designer, right-click a widget in the Object Inspector and choose your preference under Layout Alignment.
It should be quite simple:
Insert another horizontal spacer
Add Vertical spacer to Horizontal spacer (drag to widget tree)
Works in my QtCreator, should also in Your Designer :)
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With