Scrollbar width is excluded from QListView while preparing grid layout.
-
I have a QlistView with items of various sizes and with resizeMode=adjust. To distribute items evenly I override resizeEvent() and set the width of gridSize to be 1/n of the viewport width.
The problem is that the viewport width seems to be not the one which is used to arrange the grid cells.-
When the vertical scrollbar is shown, I found from testing that the width should be decreased by 1.
-
When the vertical scrollbar is hidden (I use ScrollBarAsNeeded setting), I need to (additionally to a "1" from previous) manually subtract its width (which is 14 in my case and can be deduced from the active style) in order to achieve a correct behavior. However, this approach always leaves an empty area at the (hidden) scrollbar position.
I haven't found the information about the first case, but for the second one it seems that the cause is in the method of a private class:
https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qlistview.cpp.html#_ZN16QListViewPrivate18prepareItemsLayoutEvI understand, that in some cases allowing the grid to occupy the scrollbar area can result in the blinking of the scrollbar, but, if I understand correctly, it is not my case. So, is there a way to distribute grid cells on a full viewport width when the vertical scrollbar is not shown?
-