From 35263fffeaf6085907009e1fca3fba56be1acdb7 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 16 Nov 2021 06:31:37 +0100 Subject: Always check keyboard modifiers when generating mouse events This is basically a revert of: 634ce491e8e943519593140b858eb2e67253c13e The cached keyboard modifier can get out of sync when switching to another application while a modifier is pressed. In this case we get a key press event but we might not get the key release event, which is expected to reset the cached modifier. Switching back to the Qt application after the modifier was released now still has the old modifier cached. Most prominent example is triggering alt + tab to switch to another application and use the mouse to get back to it. In this case the alt modifier is still cached. Task-number: QTCREATORBUG-26581 Pick-to: 6.2 Change-Id: I9d64b7d730af089778bd1a4b3f1296bcccd5d16d Reviewed-by: Volker Hilsheimer --- src/widgets/widgets/qplaintextedit.cpp | 4 +--- src/widgets/widgets/qplaintextedit_p.h | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index daa81512e2..9ca5bff827 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -1616,7 +1616,7 @@ void QPlainTextEdit::timerEvent(QTimerEvent *e) const QPoint globalPos = QCursor::pos(); pos = d->viewport->mapFromGlobal(globalPos); QMouseEvent ev(QEvent::MouseMove, pos, d->viewport->mapTo(d->viewport->topLevelWidget(), pos), globalPos, - Qt::LeftButton, Qt::LeftButton, d->keyboardModifiers); + Qt::LeftButton, Qt::LeftButton, QGuiApplication::keyboardModifiers()); mouseMoveEvent(&ev); } int deltaY = qMax(pos.y() - visible.top(), visible.bottom() - pos.y()) - visible.height(); @@ -1681,7 +1681,6 @@ void QPlainTextEdit::setPlainText(const QString &text) void QPlainTextEdit::keyPressEvent(QKeyEvent *e) { Q_D(QPlainTextEdit); - d->keyboardModifiers = e->modifiers(); #ifdef QT_KEYPAD_NAVIGATION switch (e->key()) { @@ -1832,7 +1831,6 @@ void QPlainTextEdit::keyReleaseEvent(QKeyEvent *e) Q_D(QPlainTextEdit); if (!isReadOnly()) d->handleSoftwareInputPanel(); - d->keyboardModifiers = e->modifiers(); #ifdef QT_KEYPAD_NAVIGATION if (QApplicationPrivate::keypadNavigationEnabled()) { diff --git a/src/widgets/widgets/qplaintextedit_p.h b/src/widgets/widgets/qplaintextedit_p.h index 112eb2e4f6..114db01574 100644 --- a/src/widgets/widgets/qplaintextedit_p.h +++ b/src/widgets/widgets/qplaintextedit_p.h @@ -155,7 +155,6 @@ public: qreal pageUpDownLastCursorY = 0; QPlainTextEdit::LineWrapMode lineWrap = QPlainTextEdit::WidgetWidth; QTextOption::WrapMode wordWrap = QTextOption::WrapAtWordBoundaryOrAnywhere; - Qt::KeyboardModifiers keyboardModifiers = {}; int originalOffsetY = 0; int topLine = 0; -- cgit v1.2.3