Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    [Solved]How to move a widget to the center of the dialog?

    General and Desktop
    5
    9
    5009
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      Leon last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • L
        Leon last edited by

        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 :)

        1 Reply Last reply Reply Quote 0
        • R
          romankr last edited by

          use layouts.

          1 Reply Last reply Reply Quote 0
          • H
            HuXiKa last edited by

            If you just want to display text in a pop-up dialog, use "QMessageBox ":http://doc.qt.nokia.com/latest/qmessagebox.html instead.

            If you can find faults of spelling in the text above, you can keep them.

            1 Reply Last reply Reply Quote 0
            • L
              Leon last edited by

              Layouts doesn't work in this case..
              No i want dialog :)

              1 Reply Last reply Reply Quote 0
              • A
                andre last edited by

                Layouts do work, but it depends on what else is on the dialog. If you want, you can position the label manually as well. It will overlap other widgets that are on the form though, then.

                1 Reply Last reply Reply Quote 0
                • L
                  Leon last edited by

                  I am ok with my first solution!
                  Layouts doesn't do what i want.. And i don't want to position the label manually cause i need accuracy!

                  1 Reply Last reply Reply Quote 0
                  • A
                    andre last edited by

                    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).

                    1 Reply Last reply Reply Quote 0
                    • T
                      tobias.hunger last edited by

                      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...

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post