summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Cape <dcape@qnx.com>2015-09-29 09:54:24 -0400
committerDan Cape <dcape@qnx.com>2017-03-13 15:47:10 +0000
commit4f324d4655a093b406134624ff753eb518429b83 (patch)
tree7cfd89df87706bfede5afa747719076f69865301
parentedf0be818cde51fcd47295171c65efd82b67ba65 (diff)
Fix item keeping hover highlight even when mouse has left it
Made change to clear the hover index when the mouse leaves the widget. This will ensure the component does not think the item still has the mouse over it. Task-number: QTBUG-46785 Change-Id: I34b7f0e171e9cf07ca23150af1b0e6e59a10a58a Reviewed-by: David Faure <david.faure@kdab.com>
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp1
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp53
2 files changed, 54 insertions, 0 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index 6ecf5a664f..319cc86c18 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -1703,6 +1703,7 @@ bool QAbstractItemView::viewportEvent(QEvent *event)
d->viewportEnteredNeeded = true;
break;
case QEvent::Leave:
+ d->setHoverIndex(QModelIndex()); // If we've left, no hover should be needed anymore
#ifndef QT_NO_STATUSTIP
if (d->shouldClearStatusTip && d->parent) {
QString empty;
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
index d241296a6b..f2cf78e8ac 100644
--- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
+++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
@@ -45,6 +45,7 @@
#include <qpushbutton.h>
#include <qscrollbar.h>
#include <qboxlayout.h>
+#include <qitemdelegate.h>
#include <qlineedit.h>
#include <qscreen.h>
#include <qscopedpointer.h>
@@ -151,6 +152,7 @@ private slots:
void testSelectionModelInSyncWithView();
void testClickToSelect();
void testDialogAsEditor();
+ void QTBUG46785_mouseout_hover_state();
};
class MyAbstractItemDelegate : public QAbstractItemDelegate
@@ -2213,5 +2215,56 @@ void tst_QAbstractItemView::testDialogAsEditor()
QCOMPARE(delegate.result, QDialog::Accepted);
}
+class HoverItemDelegate : public QItemDelegate
+{
+public:
+ HoverItemDelegate()
+ : QItemDelegate()
+ , m_paintedWithoutHover(false)
+ { }
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const override
+ {
+ Q_UNUSED(painter);
+
+ if (!(opt.state & QStyle::State_MouseOver)) {
+
+ // We don't want to set m_paintedWithoutHover for any item so check for the item at 0,0
+ if (index.row() == 0 && index.column() == 0) {
+ m_paintedWithoutHover = true;
+ }
+ }
+ }
+
+ mutable bool m_paintedWithoutHover;
+};
+
+void tst_QAbstractItemView::QTBUG46785_mouseout_hover_state()
+{
+ HoverItemDelegate delegate;
+
+ QTableWidget table(5, 5);
+ table.verticalHeader()->hide();
+ table.horizontalHeader()->hide();
+ table.setMouseTracking(true);
+ table.setItemDelegate(&delegate);
+ centerOnScreen(&table);
+ table.show();
+ QVERIFY(QTest::qWaitForWindowActive(&table));
+
+ QModelIndex item = table.model()->index(0, 0);
+ QRect itemRect = table.visualRect(item);
+
+ // Move the mouse into the center of the item at 0,0 to cause a paint event to occur
+ QTest::mouseMove(table.viewport(), itemRect.center());
+ QTest::mouseClick(table.viewport(), Qt::LeftButton, 0, itemRect.center());
+
+ delegate.m_paintedWithoutHover = false;
+
+ QTest::mouseMove(table.viewport(), QPoint(-50, 0));
+
+ QTRY_VERIFY(delegate.m_paintedWithoutHover);
+}
+
QTEST_MAIN(tst_QAbstractItemView)
#include "tst_qabstractitemview.moc"