How to correctly use Layout to maintain widget size when changing resolution
-
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:
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:
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:
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:
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:
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?
-
@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.
-
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.
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:
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?
-
@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.
-
@jsulm
Setting Horizontal Stretch to any value will increase the Connect button size: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.
-
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.