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. Layout alignment option doesn't actually align widget in QHBoxLayout
Forum Updated to NodeBB v4.3 + New Features

Layout alignment option doesn't actually align widget in QHBoxLayout

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 5 Posters 5.9k Views 4 Watching
  • 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.
  • D Offline
    D Offline
    diniamo
    wrote on last edited by
    #1

    I have 2 widgets inside of the mentioned layout, both with top vertical, and left horizontal alignment. Now the problem is that both of them get aligned to the top vertically, but the second object doesn't get aligned horizontally whatever I set for that option.

    I am using Qt 6 with C++ and forms.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please provide a minimal compilable example that shows the behaviour your describe.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        diniamo
        wrote on last edited by
        #3

        I hope a screenshot is enough.
        c4a071d3-4fce-4c31-bf68-75286509160d-image.png
        6578ecc0-6a35-4726-9984-7c19330fd613-image.png

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          While it's nice to see the result you have, not knowing how to reproduce it makes it difficult to reproduce and understand.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            diniamo
            wrote on last edited by diniamo
            #5

            Reproduction steps:

            1. Get a widget
            2. Put a VBoxLayout on it
            3. get 2 sub widgets
            4. set layout alignment to left, top for both
            5. see the second widget not aligning to the left

            Like this:
            fa9cf124-857b-4670-8bed-17dd7728f7b5-image.png

            JoeCFDJ 1 Reply Last reply
            0
            • D Offline
              D Offline
              diniamo
              wrote on last edited by
              #6

              So um, could you reproduce it? Or do you need more information?

              Thank YouT 1 Reply Last reply
              0
              • D diniamo

                So um, could you reproduce it? Or do you need more information?

                Thank YouT Offline
                Thank YouT Offline
                Thank You
                wrote on last edited by
                #7

                @diniamo

                see the second widget not aligning to the left

                following the steps what you said, both widgets are aligned to left,

                Maybe I din't understand the question or Is this the problem?

                screenshot.jpg

                Let's make QT free or It will go forever

                TRUE AND FALSE <3

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  diniamo
                  wrote on last edited by
                  #8

                  I'm sorry, I meant to say QHBoxLayout not QVBoxLayout.

                  1 Reply Last reply
                  0
                  • D diniamo

                    Reproduction steps:

                    1. Get a widget
                    2. Put a VBoxLayout on it
                    3. get 2 sub widgets
                    4. set layout alignment to left, top for both
                    5. see the second widget not aligning to the left

                    Like this:
                    fa9cf124-857b-4670-8bed-17dd7728f7b5-image.png

                    JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by JoeCFD
                    #9

                    @diniamo
                    1. Get a widget
                    2. get 2 sub widgets
                    3. right click on the widget and select layout->layout horizontally
                    you can add a spacer to right in the layout and both widgets will be squeezed to the left.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      diniamo
                      wrote on last edited by
                      #10

                      a2ec7e1b-48e1-4d34-8a6a-98cd1c7aaefb-image.png

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        diniamo
                        wrote on last edited by
                        #11

                        Nop doesn't work, now it just won't let me align the first element at all.

                        JoeCFDJ 1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          That's why a minimal compilable example is useful: people work together on the same issue in the same conditions.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • D diniamo

                            Nop doesn't work, now it just won't let me align the first element at all.

                            JoeCFDJ Offline
                            JoeCFDJ Offline
                            JoeCFD
                            wrote on last edited by JoeCFD
                            #13

                            @diniamo because it has a layout already. You are talking about something in the middle of a layout.
                            write down all steps you have done from the beginning.

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              diniamo
                              wrote on last edited by
                              #14

                              https://drive.google.com/file/d/1LPRK2Xyax7FpnLzU_JxGczKNrYjNSIxS/view?usp=sharing

                              Here, a minimal compilable example. As you can see Button2 won't move strictly to the left, next to Button1.

                              JoeCFDJ Thank YouT 2 Replies Last reply
                              0
                              • D diniamo

                                https://drive.google.com/file/d/1LPRK2Xyax7FpnLzU_JxGczKNrYjNSIxS/view?usp=sharing

                                Here, a minimal compilable example. As you can see Button2 won't move strictly to the left, next to Button1.

                                JoeCFDJ Offline
                                JoeCFDJ Offline
                                JoeCFD
                                wrote on last edited by
                                #15

                                @diniamo Not everyone has access to google drive

                                1 Reply Last reply
                                0
                                • D diniamo

                                  https://drive.google.com/file/d/1LPRK2Xyax7FpnLzU_JxGczKNrYjNSIxS/view?usp=sharing

                                  Here, a minimal compilable example. As you can see Button2 won't move strictly to the left, next to Button1.

                                  Thank YouT Offline
                                  Thank YouT Offline
                                  Thank You
                                  wrote on last edited by
                                  #16

                                  @diniamo
                                  Hello,
                                  Can you draw on paint or any other software and post here instead of linking to other platforms
                                  That will help you get your solution faster~

                                  Let's make QT free or It will go forever

                                  TRUE AND FALSE <3

                                  1 Reply Last reply
                                  0
                                  • D Offline
                                    D Offline
                                    diniamo
                                    wrote on last edited by
                                    #17

                                    Not everyone has access to google drive

                                    Sorry about that, I fixed it.

                                    But I also made a little drawing, if it's more understandable that way:
                                    layoutalignmentproblem.png

                                    mrjjM 1 Reply Last reply
                                    0
                                    • D diniamo

                                      Not everyone has access to google drive

                                      Sorry about that, I fixed it.

                                      But I also made a little drawing, if it's more understandable that way:
                                      layoutalignmentproblem.png

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      @diniamo

                                      Hi
                                      Super with both code and picture.

                                      However, its working as expected.

                                      The box layout is a bit special how it operates.
                                      When you put in 2 buttons. the area allocated to the layout is split into 2 parts of the same size.
                                      When you then ask a button to align left, it aligns left in the half area where it belongs.

                                      So it does align to the left as you can see on your picture.
                                      The right button is aligned to the left of its right part of the total area.

                                      You can press them to the left by using a Spacer

                                      alt text

                                      1 Reply Last reply
                                      0
                                      • D Offline
                                        D Offline
                                        diniamo
                                        wrote on last edited by
                                        #19

                                        OK, thank you, that makes sense, and what if I want to fill out the remeaning space with a widget, let's say a QFrame?

                                        mrjjM 1 Reply Last reply
                                        0
                                        • D diniamo

                                          OK, thank you, that makes sense, and what if I want to fill out the remeaning space with a widget, let's say a QFrame?

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by mrjj
                                          #20

                                          @diniamo
                                          Hi
                                          Then you just insert the QFrame last. and area will then be divided in 3 of same size.
                                          You can use columnStrech to alter how the space is shared.

                                          alt text

                                          Here we say we want QFrame to have more than the buttons.

                                          1 Reply Last reply
                                          3

                                          • Login

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