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. Anchoring the widgets for resizing with the form

Anchoring the widgets for resizing with the form

Scheduled Pinned Locked Moved Unsolved General and Desktop
layoutresize
22 Posts 5 Posters 12.9k 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.
  • N Offline
    N Offline
    nulluse
    wrote on 12 Apr 2016, 23:51 last edited by nulluse 4 Dec 2016, 23:51
    #1

    From quick googling it appears as if Qt does not have the anchors and I am supposed to use the layouts. But I cannot find any info on how I can anchor the layouts to the form.
    Do I need to write a signal handler to resize the layouts with the form?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 13 Apr 2016, 04:50 last edited by
      #2

      I don't understand your question.
      What anchors do you need?
      Layouts in Qt typically resize automatically if the form is resized.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 13 Apr 2016, 09:25 last edited by
        #3

        hi
        If you place something widget on a from in Designer
        and then right click the form, the last menu allows you to
        add a layout.
        This way you can add layout to most Widgets, not just forms.
        But place other widget first inside the widget/form then right click.

        http://doc.qt.io/qt-5/layout.html

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nulluse
          wrote on 13 Apr 2016, 13:43 last edited by nulluse
          #4

          I think I misunderstood the correlation between the layouts in Qt Designer and the layouts mentioned in the tutorials. I thought that by layout they meant dropping one of the very top 3 components from the Qt Designer toolbox onto a form and adding all widgets to the layout, as I did not know that layout was something different and had to be accessed through a pop up menu instead.

          M K 2 Replies Last reply 13 Apr 2016, 13:48
          0
          • N nulluse
            13 Apr 2016, 13:43

            I think I misunderstood the correlation between the layouts in Qt Designer and the layouts mentioned in the tutorials. I thought that by layout they meant dropping one of the very top 3 components from the Qt Designer toolbox onto a form and adding all widgets to the layout, as I did not know that layout was something different and had to be accessed through a pop up menu instead.

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 13 Apr 2016, 13:48 last edited by
            #5

            @nulluse
            Hi the layouts in the list with widgets is also just layouts.
            U can drag to widget to apply it.
            Should work the same, but never tested it,
            Always used right click. :)

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 13 Apr 2016, 13:51 last edited by
              #6

              Ok
              tested it.
              They do not work the same. Sort like floating layouts or for layout in layout i guess.
              Using right click will work better.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nulluse
                wrote on 13 Apr 2016, 13:53 last edited by
                #7

                Pardon my straight attitude, but this is sooooo counter intuitive!
                The anchor approach is ways more straightforward and adds ways less overhead.

                M 1 Reply Last reply 13 Apr 2016, 13:55
                0
                • N nulluse
                  13 Apr 2016, 13:53

                  Pardon my straight attitude, but this is sooooo counter intuitive!
                  The anchor approach is ways more straightforward and adds ways less overhead.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 13 Apr 2016, 13:55 last edited by
                  #8

                  @nulluse said:

                  anchor approach

                  well I used anchors in other frameworks and so far
                  Qt layouts are far better :)

                  Very easy to use and setup. even for complex layout once u get the hang of it.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 13 Apr 2016, 14:04 last edited by
                    #9

                    oh, just as a note.
                    Minimum and maximum size property is often useful with layouts.
                    Also on the layout layoutRow/colStretch if u want to change how much
                    each get. normal is 50/50
                    so if u write 2,1 the first get twice as much.
                    That was not intuitive and I still miss the ability to use %
                    But over all it works good.

                    1 Reply Last reply
                    0
                    • N nulluse
                      13 Apr 2016, 13:43

                      I think I misunderstood the correlation between the layouts in Qt Designer and the layouts mentioned in the tutorials. I thought that by layout they meant dropping one of the very top 3 components from the Qt Designer toolbox onto a form and adding all widgets to the layout, as I did not know that layout was something different and had to be accessed through a pop up menu instead.

                      K Offline
                      K Offline
                      kshegunov
                      Moderators
                      wrote on 13 Apr 2016, 18:50 last edited by
                      #10

                      @nulluse said:

                      I think I misunderstood the correlation between the layouts in Qt Designer and the layouts mentioned in the tutorials. I thought that by layout they meant dropping one of the very top 3 components from the Qt Designer toolbox onto a form and adding all widgets to the layout, as I did not know that layout was something different and had to be accessed through a pop up menu instead.

                      It's basically the same thing, only the way the code is generated is a bit different. When you drop a layout from the toolbox, it's inserted as a child layout (layouts can be nested) to the widget's layout. If your widget doesn't have a layout (which is the default) it floats around. When you use the context menu, you set the layout of the widget, hence your elements are not floating. In code this'd look like this:

                      QWidget * widget; //< The widget initialized from the form
                      
                      // This is approximately what's generated when you drag a layout from the toolbox
                      QLayout * droppedFromToolbox; //< The layout that's generated when you drag it from the toolbox
                      QLayout * widgetLayout = widget->layout();
                      if (widgetLayout)
                         widgetLayout ->addItem(droppedFromToolbox);
                      
                      // This is what's generated (again approximately) when you use the context menu.
                      QLayout * fromContextMenu; //< The layout selected from the context menu
                      widget->setLayout(fromContextMenu);
                      

                      You can see those are a bit different, but work on the same principle.

                      Kind regards.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      1
                      • N Offline
                        N Offline
                        nulluse
                        wrote on 6 May 2016, 17:08 last edited by
                        #11

                        After reading more on this I realize that the concept of layouts (also used in Android etc) is horrible comparing with straightforward, flexible and easy to set up system of anchors.
                        With the layouts you have to

                        1. set up your form for a layout before adding any widgets

                        if you missed #1 you are summarily screwed.

                        1. choose by way of trial and error the layout that least mucks up the intended design
                        2. freeze many widgets by entering min and max sizes (typing tons of numbers)

                        all instead of flipping the yes/no anchors of the widgets.

                        Looks like Qt came to their senses in Qt Quick (whatever it is) which now supports the anchors, but not in the regular .ui files.

                        To sum it up, this is a very counter-intuitive niche concept where the UI developer is totally at the mercy of the pre-defined layouts and once that is chosen, QtDesigner does not even support full undo function. If you want to support nothing but devices and smartphones, this is probably Okay, but for a normal desktop layouts are very counter-intuitive and counter-productive.

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 9 May 2016, 05:09 last edited by
                          #12

                          "niche concept"?
                          Are you sure layouts are a niche concept?
                          As far as I know Java GUI for example uses layouts as well (see https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html). I like layouts - they are very flexible and powerful.

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          1
                          • N Offline
                            N Offline
                            nulluse
                            wrote on 9 May 2016, 13:44 last edited by
                            #13

                            Adding a layout to the UI elements on a form resizes and rearranges them all and it is not possible to change their sizes once they are in a layout. How's that powerful and flexible?

                            M 1 Reply Last reply 9 May 2016, 13:50
                            0
                            • N nulluse
                              9 May 2016, 13:44

                              Adding a layout to the UI elements on a form resizes and rearranges them all and it is not possible to change their sizes once they are in a layout. How's that powerful and flexible?

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 9 May 2016, 13:50 last edited by
                              #14

                              @nulluse
                              The layout define the size.Not reversed.
                              If you dont want the layout size for all widgets ,
                              u can then adjust with min/max sizes on individual widgets.
                              You can also instruct layout if u want to be greedy and use all space/and or other options.

                              N 1 Reply Last reply 9 May 2016, 14:30
                              0
                              • M mrjj
                                9 May 2016, 13:50

                                @nulluse
                                The layout define the size.Not reversed.
                                If you dont want the layout size for all widgets ,
                                u can then adjust with min/max sizes on individual widgets.
                                You can also instruct layout if u want to be greedy and use all space/and or other options.

                                N Offline
                                N Offline
                                nulluse
                                wrote on 9 May 2016, 14:30 last edited by
                                #15

                                @mrjj said:

                                @nulluse
                                If you dont want the layout size for all widgets ,
                                u can then adjust with min/max sizes on individual widgets.
                                You can also instruct layout if u want to be greedy and use all space/and or other options.

                                Exactly! This is double work, and very tedious one, versus defining the anchors.
                                The anchors do not require defining fixed sizes.

                                M K 2 Replies Last reply 9 May 2016, 14:37
                                0
                                • N nulluse
                                  9 May 2016, 14:30

                                  @mrjj said:

                                  @nulluse
                                  If you dont want the layout size for all widgets ,
                                  u can then adjust with min/max sizes on individual widgets.
                                  You can also instruct layout if u want to be greedy and use all space/and or other options.

                                  Exactly! This is double work, and very tedious one, versus defining the anchors.
                                  The anchors do not require defining fixed sizes.

                                  M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 9 May 2016, 14:37 last edited by
                                  #16

                                  @nulluse
                                  Yeah but layouts dont either.
                                  Its assumed u want same size for all.
                                  So only if u dont , u set it.
                                  Its not double work as often NOT needed.
                                  I want same size for all anyway.
                                  and u can have margins if u want and many other nice tweaks.

                                  N 1 Reply Last reply 9 May 2016, 16:27
                                  0
                                  • N nulluse
                                    9 May 2016, 14:30

                                    @mrjj said:

                                    @nulluse
                                    If you dont want the layout size for all widgets ,
                                    u can then adjust with min/max sizes on individual widgets.
                                    You can also instruct layout if u want to be greedy and use all space/and or other options.

                                    Exactly! This is double work, and very tedious one, versus defining the anchors.
                                    The anchors do not require defining fixed sizes.

                                    K Offline
                                    K Offline
                                    kshegunov
                                    Moderators
                                    wrote on 9 May 2016, 16:12 last edited by
                                    #17

                                    @nulluse said:

                                    Exactly! This is double work, and very tedious one, versus defining the anchors.
                                    The anchors do not require defining fixed sizes.

                                    Neither do layouts. There are things called resize policies and stretch factors, which I suppose you should take a look at. Also how do you anchor two elements back to back such that one of them takes 2/3 of the space and one 1/3, ain't it necessary to go and set that manually?

                                    Read and abide by the Qt Code of Conduct

                                    1 Reply Last reply
                                    0
                                    • N Offline
                                      N Offline
                                      nulluse
                                      wrote on 9 May 2016, 16:26 last edited by
                                      #18

                                      And that's even more work vs flipping yes/no anchors and not having to worry about anything else.

                                      1 Reply Last reply
                                      0
                                      • M mrjj
                                        9 May 2016, 14:37

                                        @nulluse
                                        Yeah but layouts dont either.
                                        Its assumed u want same size for all.
                                        So only if u dont , u set it.
                                        Its not double work as often NOT needed.
                                        I want same size for all anyway.
                                        and u can have margins if u want and many other nice tweaks.

                                        N Offline
                                        N Offline
                                        nulluse
                                        wrote on 9 May 2016, 16:27 last edited by
                                        #19

                                        @mrjj said:

                                        @nulluse
                                        Yeah but layouts dont either.
                                        Its assumed u want same size for all.
                                        So only if u dont , u set it.
                                        Its not double work as often NOT needed.
                                        I want same size for all anyway.
                                        and u can have margins if u want and many other nice tweaks.

                                        You probably need to look at a system that uses anchors to realize how much more productive they allow the developers to be.

                                        1 Reply Last reply
                                        0
                                        • N Offline
                                          N Offline
                                          nulluse
                                          wrote on 21 May 2016, 19:06 last edited by
                                          #20

                                          If the layouts are so wonderful, can anyone explain why specifying a horizontal layout for a form with 3 panels adds 9 pixel margin on all sides of the form? How can that margin be eliminated?

                                          ? 1 Reply Last reply 21 May 2016, 19:25
                                          0

                                          • Login

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