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. Synchronize QFormLayouts (i.e. width of labels and widgets)
Forum Updated to NodeBB v4.3 + New Features

Synchronize QFormLayouts (i.e. width of labels and widgets)

Scheduled Pinned Locked Moved General and Desktop
17 Posts 3 Posters 7.0k Views 1 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.
  • T Offline
    T Offline
    thEClaw
    wrote on last edited by
    #5

    Sure I took a look at it. But I really don't see how the properties could help. Could you be a bit more specific?

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

      FieldGrowthPolicy -> how your widget should behave -> ExpandingFieldsGrow (you may have to modify your widget size policy)
      FormAlignment -> how your form should be aligned -> horizontally centered to the left
      LabelAlignment -> how the labels should be aligned -> to the left

      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
      • T Offline
        T Offline
        thEClaw
        wrote on last edited by
        #7

        But I don't think these are related to the problem. They only influence alignment and how far the widgets (not the labels) reach to the right. That's not really of concern.

        !http://abload.de/img/markdkj6v.png(eye sore)!
        Just to be clear: I marked the problem. The form layout chooses the necessary space according to all the labels inside itself, and that's true for all the layouts. But they don't look for sizes inside other layouts, that why the widgets don't align. There is no "anchor" or "stretch factor" I know of to circumvent that. It would be perfect if several widgets could share a single layout (so it knows about all child widgets it has to lay out), or if form layouts could have buddies. Or did I miss some kind of stretch factor that lets me influence the space distribution?

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

          Ok, I see what you mean. Currently (unless you want to create your own layout class which would be the cleanest way) the only not so dirty hack I can think of would be to get the widest string from both form layouts and then pad one of the other layout with spaces to match the longest.

          Hope it helps

          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
          • T Offline
            T Offline
            thEClaw
            wrote on last edited by
            #9

            That's "not so dirty"? Now I am interested to see what you consider dirty.^^
            In addition my application can be translated, so static solutions are impractical.

            Writing a custom layout might be the only real solution. If the different layouts cached their maximum label-width in a way that would be accessible from "friend" layouts, this might even be doable. But I suspect that these details are hidden in private classes and this seemingly easy thing will get really ugly and/or difficult.
            I also wouldn't know how to use a custom layout in Qt Designer, I am fairly new to it.

            Is there something like a static variable that can only be accessed by some instances of a class instead of all?

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

              No you're not ;)

              You can also use a QGridLayout, more code but you have more control over the row/col setup

              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
              • T Offline
                T Offline
                thEClaw
                wrote on last edited by
                #11

                Yes, I know. But I have had this problem with QFormLayout before and I thought I am just missing something - it looks like the form layout is mostly useless to me, no matter how much I like its simplicity. Can one request features somewhere?^^

                Also, I am not too sure if a grid layout wouldn't suffer from the same problem... if I had to hardcode the widths of columsn, it wouldn't be much better than the form layout I am using currently.

                PS: "I am not?" - what was that refering to?

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

                  Feature request can be done on the "bug report system":http://bugreports.qt-project.org :)

                  With the grid layout, you can play with span and stretch factor

                  You're not interested by what I consider dirty hacks ;)

                  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
                  • C Offline
                    C Offline
                    cincirin
                    wrote on last edited by
                    #13

                    [quote author="thEClaw" date="1400572586"]Also, I am not too sure if a grid layout wouldn't suffer from the same problem[/quote]

                    No it not suffer :-) See "QGridLayout::setColumnMinimumWidth":http://qt-project.org/doc/qt-4.8/qgridlayout.html#setColumnMinimumWidth

                    Also for form layout you could set the minimum width of all labels
                    @
                    foreach (QLabel* label, yourDialog->findChildren<QLabel*>())
                    label->setMiminumWidth(hack_number)
                    @

                    1 Reply Last reply
                    1
                    • T Offline
                      T Offline
                      thEClaw
                      wrote on last edited by
                      #14

                      I seemingly need an additional account for the bug report system. Maybe...

                      Setting a minimum width still is not as flexible as a form layout. As I said, translations are an option, and those might exceed the minimum width of one or several layouts (so the result would not be aligned again).

                      I might go the "custom layout route". Or just be angry with Qt for a day or two and then accept my fate.

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        cincirin
                        wrote on last edited by
                        #15

                        [quote author="thEClaw" date="1400574466"]translations are an option, and those might exceed the minimum width of one or several layouts (so the result would not be aligned again).[/quote]

                        Ok, so you know the maximum width of every label text:
                        @
                        QFontMetrics fontMetrics(label->font());
                        int width = fontMetrics.width(label->text());
                        @

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          thEClaw
                          wrote on last edited by
                          #16

                          But then the layouts have to "know" each other to find a common value or the problem I initially wanted to solve continues to exist.

                          These "hacks" are less ugly, but a custom layout would probably be the only clean solution.

                          1 Reply Last reply
                          0
                          • C Offline
                            C Offline
                            cincirin
                            wrote on last edited by
                            #17

                            I don't get your thoughts. From my point of view, this "hack" will work seemly.

                            Other alternative in your Ui design is to remove the group-box and layout the entire dialog in a form layout. Instead of having group box, place a single QLabel with a bold text to mimic the group box

                            edit: instead of QLabel I saw you have QCheckBox. So you can put a check box and enable/disable the controls programatically

                            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