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 correctly use Layout to maintain widget size when changing resolution
QtWS25 Last Chance

How to correctly use Layout to maintain widget size when changing resolution

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.0k 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.
  • L Offline
    L Offline
    lukutis222
    wrote on last edited by
    #1

    Hello everyone. I would like some clarification regarding what would be the simple and reliable method to ensure my widget size change as user increase/decrease the widget window. My QT window is as following:

    c8856024-352e-4e33-a5b7-3db1e5824954-image.png

    At the moment, if I run the program and try to increase the main widget size by dragging on its corner, it will simply create a lot of empty space:

    24e8bbb6-96e9-4cad-ad2a-9fa4e9eda838-image.png

    From what I read, this can be achieved busing Layouts. I have selected my main widget (Terminal Tab) and applied horizontal Layout. It became very weird looking:
    1a4602a9-d016-4a05-8d63-9962515c76d1-image.png

    However, despite that it looks so strange, it seem to work. I can now drag increase and decrease the size and it will change the other widget sizes automatically:
    aa5e7fa9-dd2b-4f65-9ae5-587a5b48f8c6-image.png

    My question:

    I do not want my combo boxes and labels to be like that. The only widget that I really care about is the console_read QTextEdit widget and write_box QLineEdit:
    127193af-f3f8-47c0-8a81-10d152b9d939-image.png

    I want these 2 widgets to expand when the main widget size is increased. Is it possible to apply layout only to specific elements of a widget while others remain the same?

    jsulmJ 1 Reply Last reply
    0
    • L lukutis222

      Hello everyone. I would like some clarification regarding what would be the simple and reliable method to ensure my widget size change as user increase/decrease the widget window. My QT window is as following:

      c8856024-352e-4e33-a5b7-3db1e5824954-image.png

      At the moment, if I run the program and try to increase the main widget size by dragging on its corner, it will simply create a lot of empty space:

      24e8bbb6-96e9-4cad-ad2a-9fa4e9eda838-image.png

      From what I read, this can be achieved busing Layouts. I have selected my main widget (Terminal Tab) and applied horizontal Layout. It became very weird looking:
      1a4602a9-d016-4a05-8d63-9962515c76d1-image.png

      However, despite that it looks so strange, it seem to work. I can now drag increase and decrease the size and it will change the other widget sizes automatically:
      aa5e7fa9-dd2b-4f65-9ae5-587a5b48f8c6-image.png

      My question:

      I do not want my combo boxes and labels to be like that. The only widget that I really care about is the console_read QTextEdit widget and write_box QLineEdit:
      127193af-f3f8-47c0-8a81-10d152b9d939-image.png

      I want these 2 widgets to expand when the main widget size is increased. Is it possible to apply layout only to specific elements of a widget while others remain the same?

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

      @lukutis222 said in How to correctly use Layout to maintain widget size when changing resolution:

      I do not want my combo boxes and labels to be like that

      Then put horizontal spacer to the right. You can also put these widgets into a grid layout and put a horizontal spacer on the right site of the grid layout.

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

      1 Reply Last reply
      1
      • HoMaH Offline
        HoMaH Offline
        HoMa
        wrote on last edited by
        #3

        Also: You can combine Layouts. Like: first put the „port“ and „Baudrate“ elements into one horizontal layout, do the same for the bits and parity and in the end add these layouts into one vertical layout. Use many layouts combined!

        1 Reply Last reply
        1
        • L Offline
          L Offline
          lukutis222
          wrote on last edited by
          #4

          I tried @HoMa suggestion and I think I understand how you are supposed to be using Layouts :)

          I have created multiple Horizontal layouts that are placed inside one Vertical layout. Then all vertical layouts are then combined to a "main" vertical layout.

          48e5cf95-0be6-4dfd-9ec2-7b54bc96b254-image.png

          The only issue I have right now is being able to change widget sizes while they are in inside layout and with a horizontal spacer. For example, I want to change the Connect button size:
          f0a19521-2565-44f3-8814-30b8195601f0-image.png

          It would not allow me to change the size probably because this widget is inside a vertical layout, but what If I want to make this button bigger, surely there is a way?

          jsulmJ 1 Reply Last reply
          0
          • L lukutis222

            I tried @HoMa suggestion and I think I understand how you are supposed to be using Layouts :)

            I have created multiple Horizontal layouts that are placed inside one Vertical layout. Then all vertical layouts are then combined to a "main" vertical layout.

            48e5cf95-0be6-4dfd-9ec2-7b54bc96b254-image.png

            The only issue I have right now is being able to change widget sizes while they are in inside layout and with a horizontal spacer. For example, I want to change the Connect button size:
            f0a19521-2565-44f3-8814-30b8195601f0-image.png

            It would not allow me to change the size probably because this widget is inside a vertical layout, but what If I want to make this button bigger, surely there is a way?

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

            @lukutis222 said in How to correctly use Layout to maintain widget size when changing resolution:

            but what If I want to make this button bigger

            Try to set its "sizePolicy/Horizontal Stretch" to a value bigger than 1.

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

            L 1 Reply Last reply
            0
            • jsulmJ jsulm

              @lukutis222 said in How to correctly use Layout to maintain widget size when changing resolution:

              but what If I want to make this button bigger

              Try to set its "sizePolicy/Horizontal Stretch" to a value bigger than 1.

              L Offline
              L Offline
              lukutis222
              wrote on last edited by lukutis222
              #6

              @jsulm
              Setting Horizontal Stretch to any value will increase the Connect button size:

              64d5a68b-e699-4093-837f-c62893123c98-image.png

              I have tried to it to 1, 5, 10 and other values but it does not have any different affect, It is now very big but still does not allow me to "manually" drag the button to increase/decrease the size.

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

                Hi,

                If only your button has a stretch factor then the value doesn't really matter. Set the stretch as well on your spacer. Then you can play with the numbers to give each the space you want.

                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
                1

                • Login

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