PDA

View Full Version : Calculate QListView content dimensions



Mookie
9th June 2007, 03:36
I have a QListView and need to access (or calculate) the dimensions of the contents in pixels (not the viewport() but it's contents). I have successfully done such a thing with the verticalHeader and horizontalHeader of a QTableView in the past, but I have no such header information available to me here.

It occurred to me that the scroll bars must have this information available to them somehow, otherwise they could not scale appropriately as I resize this QListView; i.e. if the viewport is too small it must calculate the ratio of the viewport dimensions to the content dimensions.

Does anyone have insight as to how the scroll bars get this information?

marcel
9th June 2007, 06:11
How about using QAbstractScrollArea::maximumViewportSize()?

Mookie
9th June 2007, 17:28
maximumViewportSize() does not correctly report the height of the contents. In my case, it is reporting a height of 472 pixels, yet my contents are more in the range of 300 pixels high. I find it's documentation a bit ambiguous.


QSize QAbstractScrollArea::maximumViewportSize () const

Returns the size of the viewport as if the scroll bars had no valid scrolling range.

I assumed initially that this would be the lower bound on the dimensions of the viewport, given the condition that no scroll bar is visible. But if I do this...

viewport()->setMaximumHeight(maximumViewportSize());

...and start enlarging the containing layout then the scrollbars become unnecessary (and hide themselves) long before I reach the maximum height. I am not sure what this function uses for it's calculations, but the scrollbars do not appear to be using it.

Mookie
9th June 2007, 19:18
Okay, I found it.

Digging through the source code of QListView, there is a protected member function called contentsSize() which is used to calculate the required minimum(), maximum(), and pageStep() for the scrollbars.

I made my own ListView, derived from QListView, and reimplemented this function as public. Maybe I'll open a bug report/feature request to have it made public in the Qt library.