Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 573
sunyata Avatar asked Jan 24 '17 11:01

sunyata


2 Answers

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

like image 122
sunyata Avatar answered Nov 08 '22 03:11

sunyata


I'm using exactly the same approach and I get rid of the blank area by creating a widget that contains my QListWidget and use :

listwidget.setFixedSize(widget.width(), listwidget.sizeHintForRow(0) * listwidget.count() + 2 * listwidget.frameWidth())

listwidget is you QListWidget object

widget is the widget that contains your QListWidget object

like image 39
syedelec Avatar answered Nov 08 '22 04:11

syedelec