Qt Forum

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

    Qt Academy Launch in California!

    Solved Problems centering a QLineEdit into a VLayout

    General and Desktop
    2
    8
    1551
    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.
    • R
      roseicollis last edited by SGaist

      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 Reply Quote 0
      • kshegunov
        kshegunov Moderators last edited by

        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 Reply Quote 0
        • R
          roseicollis @kshegunov last edited by

          @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 Reply Quote 0
          • kshegunov
            kshegunov Moderators last edited by

            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 Reply Quote 0
            • R
              roseicollis @kshegunov last edited by

              @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 Reply Quote 0
              • kshegunov
                kshegunov Moderators last edited by

                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 Reply Quote 0
                • R
                  roseicollis @kshegunov last edited by 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 :)

                  kshegunov 1 Reply Last reply Reply Quote 0
                  • kshegunov
                    kshegunov Moderators @roseicollis last edited by

                    @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 Reply Quote 0
                    • First post
                      Last post