[Qt-interest] QListView: Get indexes of visible items

Malyushytsky, Alex alex at wai.com
Wed Apr 29 00:23:57 CEST 2009


According to my understanding, it is pretty simple, if you are willing modify QT source code:

- You add to QListView class member which will store vector of indexes:
QVector<QModelIndex> lastVisible;

- then you add one line to the void QListView::paintEvent(QPaintEvent *e) (4.5 source code assumed)
.......
    d->intersectingSet(e->rect().translated(horizontalOffset(), verticalOffset()), false);
    toBeRendered = d->intersectVector;
    lastVisible =  toBeRendered; // new line

Now you have persistent list of visible indexes and the pain to maintain your version of QT.
Too many times I wanted QT did not have so strong "private" implementation.
Finally it is written for programmers and such implementation sometimes hides way too much when public interface does not provide sufficient information.

So if you don't want to maintain your version of QT, you would have to do double work and check for each item if it is visible.

Alex




-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Ingomar Wesp
Sent: Tuesday, April 28, 2009 2:13 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] QListView: Get indexes of visible items

On Monday 27 April 2009 23:09:50 Ingomar Wesp wrote:
> On Monday 27 April 2009 22:43:20 Malyushytsky, Alex wrote:
>> This might be useful for you.
>>
>> http://www.qtsoftware.com/developer/faqs/faq.2007-02-27.8405373153
>>
>> Example there is written for TableWidget, but it should be no difference
>> for any QAbstractItemView derived class as QListView is.

Ok, now I had some time to take a closer look and I'm afraid the answer in the
FAQ can not be applied to my particular problem for the following reasons:

* QListView doesn't show headers and doesn't necessarily align items in a grid
  like a QTableView does (where looking at the visible header indices would be
  sufficient to determine the min/max visible rows/columns).

* Attempting to sample the top/left, bottom/right itesm by using
  QListView::indexAt() and the viewport's dimensions is bound to fail because
  of spacing between items (there may not be an item at the specified
  coordinates).

* When allowing free movement, items can be moved/reordered by the user and
  may even overlap, which also implies that the displayed model indices
  might not be contiguous.

Seems there is no (reasonably simple) way of determining the visible items?

Best regards,
Ingo


_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."




More information about the Qt-interest-old mailing list