QAIV: Reset double-click flag in mousePressEvent

Amends 17c1ebf8bf, which introduced logic
that recognizes double clicks to avoid duplicate clicked() emits. If a
slot connected to doubleClicked opens a dialog, then the release-event
will not be seen by the item view, leaving the flag incorrectly set and
preventing the next clicked signal.

Fixes: QTBUG-97853
Pick-to: 6.2 5.15
Change-Id: Iced83e8c66a763672f522265435dc52a745227e4
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
bb10
Volker Hilsheimer 2021-11-03 08:56:04 +01:00
parent c04b5e0c8c
commit e5ebc28764
2 changed files with 39 additions and 0 deletions

View File

@ -1791,6 +1791,7 @@ bool QAbstractItemView::viewportEvent(QEvent *event)
void QAbstractItemView::mousePressEvent(QMouseEvent *event)
{
Q_D(QAbstractItemView);
d->releaseFromDoubleClick = false;
d->delayedAutoScroll.stop(); //any interaction with the view cancel the auto scrolling
QPoint pos = event->position().toPoint();
QPersistentModelIndex index = indexAt(pos);

View File

@ -49,6 +49,7 @@
#include <QStringListModel>
#include <QStyledItemDelegate>
#include <QTableWidget>
#include <QTimer>
#include <QTreeWidget>
#include <QTest>
#include <QVBoxLayout>
@ -159,6 +160,7 @@ private slots:
void dragSelectAfterNewPress();
void dragWithSecondClick_data();
void dragWithSecondClick();
void clickAfterDoubleClick();
void selectionCommand_data();
void selectionCommand();
void mouseSelection_data();
@ -2763,6 +2765,42 @@ void tst_QAbstractItemView::dragWithSecondClick()
QTest::mouseRelease(view->viewport(), Qt::LeftButton, Qt::NoModifier, dragTo);
}
void tst_QAbstractItemView::clickAfterDoubleClick()
{
QTableWidget view(5, 5);
view.horizontalHeader()->hide();
view.verticalHeader()->hide();
view.setEditTriggers(QAbstractItemView::NoEditTriggers);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
const QModelIndex index = view.model()->index(1, 1);
QVERIFY(index.isValid());
const QPoint clickPoint = view.visualRect(index).center();
// must use the QWindow overloads so that modality is respected
QWindow *window = view.window()->windowHandle();
int clickCount = 0;
connect(&view, &QAbstractItemView::doubleClicked, [&]{
QDialog dialog(&view);
dialog.setModal(true);
QTimer::singleShot(0, [&]{ dialog.close(); });
dialog.exec();
});
connect(&view, &QAbstractItemView::clicked, [&]{
++clickCount;
});
QTest::mouseClick(window, Qt::LeftButton, {}, clickPoint);
QCOMPARE(clickCount, 1);
// generates a click followed by a double click; double click opens
// dialog that eats second release
QTest::mouseDClick(window, Qt::LeftButton, {}, clickPoint);
QCOMPARE(clickCount, 2);
QTest::mouseClick(window, Qt::LeftButton, {}, clickPoint);
QCOMPARE(clickCount, 3);
}
void tst_QAbstractItemView::selectionCommand_data()
{
QTest::addColumn<QAbstractItemView::SelectionMode>("selectionMode");