PDA

View Full Version : QGridLayout overlapping items



Santa.fat
30th October 2015, 18:39
hi friends.

i have some items in a QGridLayout that fine horizontally but vertically overlapped.
when i reduce minimum size of items they are fine but when i increase their size overlapping happens.
this is my code



for number in range(len(items)):
lbl = QLabel()
lbl.setMinimumSize(item_size)
lbl.setContentsMargins(0, 0, 0, 0)
grid_layout.addWidget(lbl, number, 1, 1, 1)

ChrisW67
30th October 2015, 19:20
Overlapping what? There is only one row of labels in the grid layout, so i guess you mean it overlaps other widgets on a form. The usual reason would be that your grid layout has not been correctly added to the parent widget's layout.

Santa.fat
30th October 2015, 19:28
i have around 300 labels that they overlapping each other vertically and the for loop that is in my code while loop for 300 times and each time it add a label to it's corresponding row in gridlayout. like this picture


11477

ChrisW67
30th October 2015, 20:11
Sorry, my bad, there is a single column of widgets.

The layout is given a fixed vertical space to divide between the widgets in the layout. It does this by resizing the widgets so they fit without overlapping. If you are placing 300 widgets in a fixed vertical space then they generally are allocated very little vertical space each. If you then try to force the individual widgets to be larger than the height the layout has to work with then the layout cannot function normally and something has to give, probably leading to the situation I cannot see in your thumbnail.

It seems that you expect the parent widget to grow to accommodate the layout content and not the other way around. Is that the case?

Santa.fat
30th October 2015, 20:42
i did not think layout have a fixed space.
when number of items is less (around 100) overlapping not happens but when number of items increases overlapping happening

this picture is normal situation (100 items)
11478

in the case of 300 items or more top of next item overlapping bottom of previous item