diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
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" |