View Full Version : QListView resize

27th May 2013, 11:04
Hi all!
I have an issue, which currently works for me, but I'd like to understand the details.
My application use custom popup menu made of QListView inside QWidget. The problem is it's height.
I'd like to count required height and resize to it or resize widget to smaller according to position/height (when smaller, QScrollBar appears).
The code is in PyQt, but it doesn't matter IMHO.

When initialize an application, I set custom font. This is strange - it works with size 10, but it works incorrectly with size 9
app.setFont(QtGui.QFont("Helvetica", 10))

According documentation, lineSpacing is height of label plus spacing to next label
self.__line_size = QtGui.QFontMetrics(QtGui.qApp.font()).lineSpacing( )

This should be the inner QListView size, but when use font size 9, the result is (?sometimes?) smaller than it should be
items_size_needed = self.__line_size * (self.view.model().rowCount()) + QtGui.QFontMetrics(QtGui.qApp.font()).overlinePos( )

At the end, I resize it this way:
self.view.resize(self.__width, items_size_needed)

Can anyone explain to me, what's wrong in my understanding?