[Solved]How to move a widget to the center of the dialog?
-
So you have a dialog and a label with a text..
For alignment it is center at both horizontal and vertical..
But i want the label to be at the center of the dialog not only the text of the label to be at the center of it..@ ui->label->rect().center();@
or
@ui->label->setAlignment(Qt::AlignCenter);@
doesn't work..So? -
-
If you just want to display text in a pop-up dialog, use "QMessageBox ":http://doc.qt.nokia.com/latest/qmessagebox.html instead.
-
Positioning manually, in this sense, means through code. You can get pixel precision that way. The best place to put such code is in the QWidget::resizeEvent handler. That way, your label will stay in the center of the dialog even if there is a layout change (like a user resizing the dialog).
-
bq. There is one noob solution.. Setting the width of the label the same as the window and the X position to 0.. So the text will be at center and no need for the label to be at center.. But if there is another solution for this i would be glad to know :)
Which is what a layout does for you...