diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-11-19 15:24:20 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-11-19 15:54:06 (GMT) |
commit | 6fd6879564929a672e9f0a5b59d9d42612e51c5a (patch) | |
tree | d7b09b92fdc41a739d66ef4442b6d18ed9617cec /src/gui/itemviews | |
parent | c48ba6b516b46775439dc3c86b21bf9ce9c7f23a (diff) | |
download | Qt-6fd6879564929a672e9f0a5b59d9d42612e51c5a.zip Qt-6fd6879564929a672e9f0a5b59d9d42612e51c5a.tar.gz Qt-6fd6879564929a672e9f0a5b59d9d42612e51c5a.tar.bz2 |
Item views: make sure the hovered item is updated when scrolling
Reviewed-by: leo
Diffstat (limited to 'src/gui/itemviews')
-rw-r--r-- | src/gui/itemviews/qabstractitemview.cpp | 35 | ||||
-rw-r--r-- | src/gui/itemviews/qabstractitemview_p.h | 2 |
2 files changed, 21 insertions, 16 deletions
diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 23bef12..c691fe2 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -138,10 +138,22 @@ void QAbstractItemViewPrivate::init() #endif } +void QAbstractItemViewPrivate::setHoverIndex(const QPersistentModelIndex &index) +{ + Q_Q(QAbstractItemView); + if (hover == index) + return; + + q->update(hover); //update the old one + hover = index; + q->update(hover); //update the new one +} + void QAbstractItemViewPrivate::checkMouseMove(const QPersistentModelIndex &index) { //we take a persistent model index because the model might change by emitting signals Q_Q(QAbstractItemView); + setHoverIndex(index); if (viewportEnteredNeeded || enteredIndex != index) { viewportEnteredNeeded = false; @@ -1536,22 +1548,13 @@ bool QAbstractItemView::viewportEvent(QEvent *event) { Q_D(QAbstractItemView); switch (event->type()) { - case QEvent::HoverEnter: { - QHoverEvent *he = static_cast<QHoverEvent*>(event); - d->hover = indexAt(he->pos()); - update(d->hover); - break; } - case QEvent::HoverLeave: { - update(d->hover); // update old - d->hover = QModelIndex(); - break; } - case QEvent::HoverMove: { - QHoverEvent *he = static_cast<QHoverEvent*>(event); - QModelIndex old = d->hover; - d->hover = indexAt(he->pos()); - if (d->hover != old) - d->viewport->update(visualRect(old)|visualRect(d->hover)); - break; } + case QEvent::HoverMove: + case QEvent::HoverEnter: + d->setHoverIndex(indexAt(static_cast<QHoverEvent*>(event)->pos())); + break; + case QEvent::HoverLeave: + d->setHoverIndex(QModelIndex()); + break; case QEvent::Enter: d->viewportEnteredNeeded = true; break; diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h index c691f61..f1ba874 100644 --- a/src/gui/itemviews/qabstractitemview_p.h +++ b/src/gui/itemviews/qabstractitemview_p.h @@ -152,6 +152,8 @@ public: const QEvent *event) const; virtual void selectAll(QItemSelectionModel::SelectionFlags command); + void setHoverIndex(const QPersistentModelIndex &index); + void checkMouseMove(const QPersistentModelIndex &index); inline void checkMouseMove(const QPoint &pos) { checkMouseMove(q_func()->indexAt(pos)); } |