Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]How to move a widget to the center of the dialog?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 5.8k Views
  • 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 Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    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
    0
    • L Offline
      L Offline
      Leon
      wrote on last edited by
      #2

      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
      0
      • R Offline
        R Offline
        romankr
        wrote on last edited by
        #3

        use layouts.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          HuXiKa
          wrote on last edited by
          #4

          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
          0
          • L Offline
            L Offline
            Leon
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              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
              0
              • L Offline
                L Offline
                Leon
                wrote on last edited by
                #7

                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
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  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
                  0
                  • T Offline
                    T Offline
                    tobias.hunger
                    wrote on last edited by
                    #9

                    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
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved