Search code examples
qtpyqtqt5pyqt5qlistwidget

Getting rid of blank area at the bottom of a QListWidget


I'm using QListWidget with setItemWidget and when adding items to the list and scrolling down to the bottom I get this result:

enter image description here

So there's an area which is completely blank at the bottom (not selectable, in the image above the last item in the list has been selected)

How can I get rid of this blank area at the bottom of the list?

Please note that the height of the rows can be different within a list

Grateful for help and with kind regards, Tord


Solution

  • It's possible to change the type of vertical scrolling that is done for list by using setVerticalScrollMode for the QListWidget so that the scrolling is done per pixel (instead of per item which is the default):

    self.list_widget.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)

    The result is that rows that are in the top-most part of the QListWidget box can be drawn only in part, which in turn means that the blank area that exists when scrolling per item will disappear:

    enter image description here

    Reference documentation: https://doc.qt.io/qt-5/qabstractitemview.html#verticalScrollMode-prop