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. QHBoxLayout, QVBoxLayout, QBoxLayout or other?
Forum Updated to NodeBB v4.3 + New Features

QHBoxLayout, QVBoxLayout, QBoxLayout or other?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 5 Posters 4.7k 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #3

    Hi
    Did you check out
    http://doc.qt.io/qt-5/qformlayout.html#details

    its what i often use for xxx | yyy layouts.

    1 Reply Last reply
    3
    • M mostefa

      Hi @JNBarchan

      I think that the QGridLayout is more appropriate for your needs

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #4

      @mostefa , @mrjj
      Thanks for suggestions, will investigate.

      Could you just comment on: if code does use QVboxLayout parent + multiple-QHboxLayout children, and the QHBoxLayouts each have multiple (but same number of) widgets added to them, do the "columns" of child widgets actually line up? I.e. does Qt left to itself do anything about making sibling QHBoxLayouts have same column widths? Otherwise perhaps in existing code they are just divided up like 50% each for two, so they line up, or perhaps existing code sets fixed widths?

      M 1 Reply Last reply
      0
      • JonBJ JonB

        @mostefa , @mrjj
        Thanks for suggestions, will investigate.

        Could you just comment on: if code does use QVboxLayout parent + multiple-QHboxLayout children, and the QHBoxLayouts each have multiple (but same number of) widgets added to them, do the "columns" of child widgets actually line up? I.e. does Qt left to itself do anything about making sibling QHBoxLayouts have same column widths? Otherwise perhaps in existing code they are just divided up like 50% each for two, so they line up, or perhaps existing code sets fixed widths?

        M Offline
        M Offline
        mostefa
        wrote on last edited by mostefa
        #5

        @JNBarchan said in QHBoxLayout, QVBoxLayout, QBoxLayout or other?:

        if code does use QVboxLayout parent + multiple-QHboxLayout children, and the QHBoxLayouts each have multiple (but same number of) widgets added to them, do the "columns" of child widgets actually line up? I.e. does Qt left to itself do anything about making sibling QHBoxLayouts have same column widths?

        if code does use QVboxLayout parent + multiple-QHboxLayout children, and the QHBoxLayouts each have multiple (but same number of) widgets added to them, do the "columns" of child widgets actually line up?

        No, there is no automatic alignement in this case , you can achieve a good alignement , but you have to play with (column stretch , row stretch...)

        Trust me using QGridLayout , or QFormLayout will offer you more comfort , by using one of them you can maintain your code more easily in the future.

        JonBJ 1 Reply Last reply
        1
        • M mostefa

          @JNBarchan said in QHBoxLayout, QVBoxLayout, QBoxLayout or other?:

          if code does use QVboxLayout parent + multiple-QHboxLayout children, and the QHBoxLayouts each have multiple (but same number of) widgets added to them, do the "columns" of child widgets actually line up? I.e. does Qt left to itself do anything about making sibling QHBoxLayouts have same column widths?

          if code does use QVboxLayout parent + multiple-QHboxLayout children, and the QHBoxLayouts each have multiple (but same number of) widgets added to them, do the "columns" of child widgets actually line up?

          No, there is no automatic alignement in this case , you can achieve a good alignement , but you have to play with (column stretch , row stretch...)

          Trust me using QGridLayout , or QFormLayout will offer you more comfort , by using one of them you can maintain your code more easily in the future.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #6

          @mostefa
          Thanks, that (lack of alignemnt in separate QHBoxLayouts) confirms what I suspected.

          I will indeed look at using QGridLayout/QFormLayout for new code I write. My question was because I wonder how the existing code has achieved columnar layout using only QV/HBoxLayout, when i don't fancy trawling through it all to understand. I have a feeling it might be using fixed-width columns on each QHBoxLayout and that's how they achieved the alignment, but it doesn't matter going forward.

          mzimmersM 1 Reply Last reply
          1
          • JonBJ JonB

            @mostefa
            Thanks, that (lack of alignemnt in separate QHBoxLayouts) confirms what I suspected.

            I will indeed look at using QGridLayout/QFormLayout for new code I write. My question was because I wonder how the existing code has achieved columnar layout using only QV/HBoxLayout, when i don't fancy trawling through it all to understand. I have a feeling it might be using fixed-width columns on each QHBoxLayout and that's how they achieved the alignment, but it doesn't matter going forward.

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #7

            @JNBarchan my two cents worth is to use the form layout. The code you mentioned, if it didn't use forms or grids, probably used some other constructs (like setting fixed sizes) to get the alignment you saw. Anyway, forms are meant for just what you're doing. Grids would be fine too.

            1 Reply Last reply
            0
            • JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #8

              OK then in that case, anyone care to summarize the difference of QGridLayout versus QFormLayout, e.g. which one is one more lightweight for my presumably minimal needs?

              mzimmersM 1 Reply Last reply
              0
              • JonBJ JonB

                OK then in that case, anyone care to summarize the difference of QGridLayout versus QFormLayout, e.g. which one is one more lightweight for my presumably minimal needs?

                mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #9

                @JNBarchan well QFormLayout is a two-column layout designed for input devices and their labels...seems precisely right for you. QGridLayout is more general purpose. In actuality, I'd expect the difference in coding effort and performance to be minimal, but you might as well use something that's tailor-made for your purpose.

                JonBJ 1 Reply Last reply
                1
                • mzimmersM mzimmers

                  @JNBarchan well QFormLayout is a two-column layout designed for input devices and their labels...seems precisely right for you. QGridLayout is more general purpose. In actuality, I'd expect the difference in coding effort and performance to be minimal, but you might as well use something that's tailor-made for your purpose.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #10

                  @mzimmers

                  designed for input devices and their labels
                  By "devices" do you mean "controls/widgets"?

                  I think you're saying QFormLayout is for:

                  Label1     Input1
                  Label2     Combo2
                  Label3     Checkbox3
                  

                  I see the point of that. Funnily enough, though, although I (presently, but might change) do have 2 columns, it's a bit different here, it's something like

                  Button1    Explanatory text of why you might like to click the button :)
                  Button2    Explanatory text ....
                  

                  Since I'm not really sure what I might end up with, but I know there will be columnar alignment required whatever, I might rather look into QGridLayout....

                  1 Reply Last reply
                  0
                  • mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by
                    #11

                    Yes, you did a better job wording it than I did. If you need the option of adding additional columns, then you'll want to use QGridLayout.

                    1 Reply Last reply
                    1
                    • mranger90M Offline
                      mranger90M Offline
                      mranger90
                      wrote on last edited by
                      #12

                      Slightly off topic, but if all you want to display is an explanation of the proper usage for the button, why not use a tool tip? That's what a tool tip is supposed to do without taking up screen real estate.

                      JonBJ 1 Reply Last reply
                      0
                      • mranger90M mranger90

                        Slightly off topic, but if all you want to display is an explanation of the proper usage for the button, why not use a tool tip? That's what a tool tip is supposed to do without taking up screen real estate.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #13

                        @mranger90
                        Because my stakeholders/users demand an on-screen explanation in this context. (Screen estate is not limited because this is the totality of this page.) Because they are fussy, pampered users who won't look at a tooltip (won't even see it --- "You mean I have to move the mouse?") and will moan if the layout is not exactly what they have decided they want, claiming they cannot possibly know what the buttons might do.

                        Not nice friendly, co-operative, open-minded, tolerant developers.

                        Get the picture? ;-)

                        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