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>
This commit is contained in:
parent
edf0be818c
commit
4f324d4655
@ -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;
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user