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. How to reduce the distance between components in Qt layout?
Forum Updated to NodeBB v4.3 + New Features

How to reduce the distance between components in Qt layout?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 300 Views 2 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.
  • IPlayGenji6I Offline
    IPlayGenji6I Offline
    IPlayGenji6
    wrote on last edited by
    #1

    In a Widget with a vertical layout, I have a QLabel and a QGridLayout. In the layout properties of this Widget, the layoutSpacing is set to only 5. However, in both the preview and actual program execution, there is a significant gap between the QLabel and the QGridLayout. Furthermore, when I continue to stretch the window vertically, this gap keeps increasing (the vertical policy of widgets in QGridLayout is set to preferred). I want the distance between the sub-layouts to remain fixed and very small while stretching the window. How can I solve this problem?
    QQ截图20230706171407.png
    QQ截图20230706172008.png
    This is the layout property of the largest widget.
    QQ截图20230706171636.png

    Gojir4G M 2 Replies Last reply
    0
    • IPlayGenji6I IPlayGenji6

      In a Widget with a vertical layout, I have a QLabel and a QGridLayout. In the layout properties of this Widget, the layoutSpacing is set to only 5. However, in both the preview and actual program execution, there is a significant gap between the QLabel and the QGridLayout. Furthermore, when I continue to stretch the window vertically, this gap keeps increasing (the vertical policy of widgets in QGridLayout is set to preferred). I want the distance between the sub-layouts to remain fixed and very small while stretching the window. How can I solve this problem?
      QQ截图20230706171407.png
      QQ截图20230706172008.png
      This is the layout property of the largest widget.
      QQ截图20230706171636.png

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by Gojir4
      #2

      @IPlayGenji6 Set 0,1 to layout stretch property for giving all the space to the second item of your widget's layout.

      IPlayGenji6I 1 Reply Last reply
      0
      • IPlayGenji6I IPlayGenji6

        In a Widget with a vertical layout, I have a QLabel and a QGridLayout. In the layout properties of this Widget, the layoutSpacing is set to only 5. However, in both the preview and actual program execution, there is a significant gap between the QLabel and the QGridLayout. Furthermore, when I continue to stretch the window vertically, this gap keeps increasing (the vertical policy of widgets in QGridLayout is set to preferred). I want the distance between the sub-layouts to remain fixed and very small while stretching the window. How can I solve this problem?
        QQ截图20230706171407.png
        QQ截图20230706172008.png
        This is the layout property of the largest widget.
        QQ截图20230706171636.png

        M Offline
        M Offline
        mpergand
        wrote on last edited by
        #3

        @IPlayGenji6
        If you want the widgets to stay on top, add a spacer to the vertical layout.

        1 Reply Last reply
        1
        • Gojir4G Gojir4

          @IPlayGenji6 Set 0,1 to layout stretch property for giving all the space to the second item of your widget's layout.

          IPlayGenji6I Offline
          IPlayGenji6I Offline
          IPlayGenji6
          wrote on last edited by
          #4

          @Gojir4 I tried it, but it only works when previewing in Qt Designer, but the program runs with the same gaps as before.

          jsulmJ IPlayGenji6I 2 Replies Last reply
          0
          • IPlayGenji6I IPlayGenji6

            @Gojir4 I tried it, but it only works when previewing in Qt Designer, but the program runs with the same gaps as before.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @IPlayGenji6 Then please show how you added a spacer.

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

            1 Reply Last reply
            0
            • IPlayGenji6I IPlayGenji6

              @Gojir4 I tried it, but it only works when previewing in Qt Designer, but the program runs with the same gaps as before.

              IPlayGenji6I Offline
              IPlayGenji6I Offline
              IPlayGenji6
              wrote on last edited by
              #6

              @IPlayGenji6 Already fixed, I didn't find that there was a widget in the QGridLayout with the vertical policy set to fixed

              1 Reply Last reply
              0
              • IPlayGenji6I IPlayGenji6 has marked this topic as solved on

              • Login

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