Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change resize behavior in Qt layouts

I want my custom widgets to gain extra space when the dialog is resized. This was working when I only had a handful of widgets, but after adding several more columns of these same widgets and putting them in a QGridLayout, the extra space merely goes in as padding between the widgets.

like image 288
Corey D Avatar asked Nov 29 '22 05:11

Corey D


1 Answers

I've had trouble with this in the past and here are some of the things I've found:

  1. First make sure all the widgets you want to expand have sizePolicy set to "Expanding".

  2. Make sure the widgets that make up your custom widgets are in a layout that allows for expanding. You can check this by just adding one of your custom widgets to the window and seeing that it expands as expected.

  3. Make sure any widgets on the form that you do not want to expand have a fixed (minimum=maximum) size in the dimension you want them to stay static.

  4. Sometimes the grid layout causes some weird spacing issues because rows are resized based on the largest widget in the entire row and similarly for columns. For some layouts, it is better to use a vertical layout that contains horizontal layouts or vica versa to create a grid-like effect. Only this way, each sub-layout is spaced independently of the other rows or columns.

like image 167
Jason B Avatar answered Dec 26 '22 23:12

Jason B