Home > Enterprise >  How to automatically adjust the elements of QGridLayout to fit in a row when the screen window size
How to automatically adjust the elements of QGridLayout to fit in a row when the screen window size

Time:10-31

I have created a scroll area and set the layout to a grid in qt designer. Then I added some frames(city profile) with fixed sizes inside the scroll area(QGridLayout). I'm trying to dynamically add or delete the city profile frames. When I add "city profile" to the grid layout, it should adapt the position automatically according to the screen size. Like, when the window is not maximized, in one row, it should show only four or five "city profile" frames but when the window is maximized, there is more space in the row and it should occupy more "city profile" frames in a single row. I tried setting the layout size constraint but it's not giving the output I want. Also, I have googled about it but couldn't find any results.

Demo Image when the window is in normal view enter image description here

Demo Image when the window is maximized enter image description here

Markings

enter image description here

CodePudding user response:

you can use this python code for the screenshot at startup

And after resizing:

screenshot with different layout

Note that if you plan on displaying lots of items (in the order of hundreds or thousands), then you should consider using a custom delegate instead of index widgets, which allows advanced and custom painting and is much lighter for bigger models.

  • Related