diff options
Diffstat (limited to 'src/gui/itemviews/qabstractitemview.cpp')
-rw-r--r-- | src/gui/itemviews/qabstractitemview.cpp | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 23bef12004..ad15655b9c 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -96,6 +96,7 @@ QAbstractItemViewPrivate::QAbstractItemViewPrivate() autoScrollMargin(16), autoScrollCount(0), shouldScrollToCurrentOnShow(false), + shouldClearStatusTip(false), alternatingColors(false), textElideMode(Qt::ElideRight), verticalScrollMode(QAbstractItemView::ScrollPerItem), @@ -138,10 +139,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; @@ -149,14 +162,15 @@ void QAbstractItemViewPrivate::checkMouseMove(const QPersistentModelIndex &index emit q->entered(index); #ifndef QT_NO_STATUSTIP QString statustip = model->data(index, Qt::StatusTipRole).toString(); - if (parent && !statustip.isEmpty()) { + if (parent && (shouldClearStatusTip || !statustip.isEmpty())) { QStatusTipEvent tip(statustip); QApplication::sendEvent(parent, &tip); + shouldClearStatusTip = !statustip.isEmpty(); } #endif } else { #ifndef QT_NO_STATUSTIP - if (parent) { + if (parent && shouldClearStatusTip) { QString emptyString; QStatusTipEvent tip( emptyString ); QApplication::sendEvent(parent, &tip); @@ -1536,26 +1550,25 @@ 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; case QEvent::Leave: + #ifndef QT_NO_STATUSTIP + if (d->shouldClearStatusTip && d->parent) { + QString empty; + QStatusTipEvent tip(empty); + QApplication::sendEvent(d->parent, &tip); + d->shouldClearStatusTip = false; + } + #endif d->enteredIndex = QModelIndex(); break; case QEvent::ToolTip: |