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. Problems centering a QLineEdit into a VLayout

Problems centering a QLineEdit into a VLayout

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 2.1k 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.
  • R Offline
    R Offline
    roseicollis
    wrote on last edited by SGaist
    #1

    Hi,

    I have a QWizardPAge where I have a Vertical layout (Vlay = new QVBoxLayout();) and inside it i have a label (QLabel *my_label) and then a QLineEdit (QLineEdit *le_Per;)
    I add the Vertical layout to the general one like this:

        this->getLayout()->addLayout(this->Vlay);
    

    Until here its all okey, I see the label and down of it I see the LineEdit BUT then I want the LineEdit centered on the screen, so I tried with:

    Vlay->setAlignment(le_Per,Qt::Align);
    

    But its still on the left side of the screen. I just want the lineEdit on the center, the label must be on the left side to be easy to read as it is 2 lines long of information.

    I've trie d too with:

    le_Per->setStyleSheet("QLineEdit{margin-left: 100px;}");
    

    But instead of moving the all widget, it moves the start of it and not the end so the widget becomes shorter than it was so... if I try to center it with a 300px the widget (LineEdit) dissapears .

    Thank you so much!

    1 Reply Last reply
    0
    • kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      Hello,
      If I understand the question correctly, hopefully I do, you could insert a spacer to left and right of the line edit. That should do the trick. Here is a quick reference: http://doc.qt.io/qt-5/qspaceritem.html

      Kind regards.

      Read and abide by the Qt Code of Conduct

      R 1 Reply Last reply
      0
      • kshegunovK kshegunov

        Hello,
        If I understand the question correctly, hopefully I do, you could insert a spacer to left and right of the line edit. That should do the trick. Here is a quick reference: http://doc.qt.io/qt-5/qspaceritem.html

        Kind regards.

        R Offline
        R Offline
        roseicollis
        wrote on last edited by
        #3

        @kshegunov I've see some examples but if I am right, I will need a HLayout also wich I'm trying to avoid (to minimize the quantity of widgets)

        1 Reply Last reply
        0
        • kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          Yes, you will probably do. Widgets are pretty thin (resources-wise) so in most cases creating lots of them is not a problem. For your problem you might also consider a form or a grid layout, they might be a more suitable choice.

          Read and abide by the Qt Code of Conduct

          R 1 Reply Last reply
          0
          • kshegunovK kshegunov

            Yes, you will probably do. Widgets are pretty thin (resources-wise) so in most cases creating lots of them is not a problem. For your problem you might also consider a form or a grid layout, they might be a more suitable choice.

            R Offline
            R Offline
            roseicollis
            wrote on last edited by
            #5

            @kshegunov I've had to say that I was trying to avoid using more widgets like the HLayout . I'll consider your option about the form and the grid if I can't do it withouth adding more widgets.

            Thank you so much!

            1 Reply Last reply
            0
            • kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              You are welcome. If you are satisfied with the answer, please mark the question as solved.
              Good luck.

              Read and abide by the Qt Code of Conduct

              R 1 Reply Last reply
              0
              • kshegunovK kshegunov

                You are welcome. If you are satisfied with the answer, please mark the question as solved.
                Good luck.

                R Offline
                R Offline
                roseicollis
                wrote on last edited by roseicollis
                #7

                @kshegunov yes yes I know how that page works, but thanks for remind me it. It doesn't really satisfy me because it's not how I want it to work but yes, it does answer my question correctly :)

                kshegunovK 1 Reply Last reply
                0
                • R roseicollis

                  @kshegunov yes yes I know how that page works, but thanks for remind me it. It doesn't really satisfy me because it's not how I want it to work but yes, it does answer my question correctly :)

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @roseicollis
                  I don't change the page, but there is a button at the bottom Thread tools or something like this, when you click it there should be a Mark as solved option. ;)
                  Kind regards.

                  Read and abide by the Qt Code of Conduct

                  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