Results 1 to 4 of 4

Thread: Calculate QListView content dimensions

  1. #1
    Join Date
    Jun 2006
    Posts
    43
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Calculate QListView content dimensions

    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?
    Last edited by Mookie; 9th June 2007 at 03:38. Reason: Subject not descriptive enough

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Calculate QListView content dimensions


  3. #3
    Join Date
    Jun 2006
    Posts
    43
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Calculate QListView content dimensions

    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.

  4. #4
    Join Date
    Jun 2006
    Posts
    43
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Cool Re: Calculate QListView content dimensions

    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.

Similar Threads

  1. QListView word wrap
    By serega in forum Qt Programming
    Replies: 17
    Last Post: 30th August 2007, 04:13
  2. QListView multiSelection
    By cristiano in forum Qt Programming
    Replies: 3
    Last Post: 20th December 2006, 00:41
  3. Replies: 0
    Last Post: 10th November 2006, 14:46
  4. QTable..Vs.. QListView
    By :db:sStrong in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 22:03
  5. Keeping focus at bottom of QListView
    By jakamph in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2006, 15:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.