Limit height of the QListWidget to accomodate only single row
-
I have a
QListWidget
which always shows three items with icons aligned from left to right. Despite this the height of the widget is too big and it looks ugly and occupies too much space.
Is it possible to make list widget show only single row, something like in the image below
I tried to play with thesizePolicy
property to make it smaller, but could not get desired result. Also I do not want to hardcode size, as it might not work correctly with different themes/dpi/font or icon sizes.Any ideas how to achieve this?
-
You have to manually set the size of your QListWidget to your desired size. It will not resize automatically to the size of the contents.
-
Hi,
Beside the suggestion of @Christian-Ehrlicher, are you using a layout ?
-
@Christian-Ehrlicher thanks, but if I understand correctly (and as mentioned in the starting post), this way it will not work correctly with different themes/font sizes/screen dpi. Or am I miss something?
-
Kind of solved. If I set
sizeAdjustPolicy
toAdjustToContents
andsizePolicy
toMaximum
, the list widget size will adjust to accomodate items plus small margins around them. I'm quite happy with the result, it would be even better if I could make items equally distribute across available space, but even now it looks good enough.