diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-07-06 15:59:37 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-07-08 09:41:29 +0200 |
commit | e44edaac2c575df9b2f065b18b716cb21a0c2b75 (patch) | |
tree | 7a85994c2ca8c112b209ca75e57b0fdb0efd5ac5 /src/widgets | |
parent | 66a30b9a33aac288335f32ea9dc8dd8542abf69f (diff) |
QWidget: use WA_InputMethodEnabled when ImEnabled is not implemented
In Qt 6.3, a check for WA_InputMethodEnabled was removed
in QWidget, to support IM queries also for read-only
widgets (7c6e4af48). This caused a regression on iOS, which
made the input panel open for widgets that didn't support
IM at all.
A patch was merged that solved the regression (3b12305575),
but it didn't take the widget attribute into account.
Since not doing so has the potential to cause regressions,
this patch will modify the affected code once more, so that
we instead fall back to test WA_InputMethodEnabled when
ImEnabled is not implemented. This will match closely
to the way ImEnabled was implemented in Qt 6.2.
Since we, with this change, now require that either ImEnabled
or WA_InputMethodEnabled is set, our own input widgets will
fail to support IM text selection when they're read-only, since
they actually don't implement ImEnabled.
This patch will therefore also make sure that we do so.
Task-number: QTBUG-104527
Pick-to: 6.4 6.3
Change-Id: I70ad910aec38d0a74f4dd7d3115d3c45c16d2b3b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsitem.cpp | 4 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 15 | ||||
-rw-r--r-- | src/widgets/widgets/qlineedit.cpp | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qplaintextedit.cpp | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qtextedit.cpp | 2 |
5 files changed, 15 insertions, 10 deletions
diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index f2d2339c97..9008b54d84 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -10274,7 +10274,9 @@ void QGraphicsTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) QVariant QGraphicsTextItem::inputMethodQuery(Qt::InputMethodQuery query) const { QVariant v; - if (query == Qt::ImHints) + if (query == Qt::ImEnabled) + return isEnabled(); + else if (query == Qt::ImHints) v = int(inputMethodHints()); else if (dd->control) v = dd->control->inputMethodQuery(query, QVariant()); diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 1160471194..f0da19f9c8 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -8898,15 +8898,12 @@ bool QWidget::event(QEvent *event) QVariant v = inputMethodQuery(q); if (q == Qt::ImEnabled && !v.isValid() && isEnabled()) { // Qt:ImEnabled was added in Qt 5.3. So not all widgets support it, even - // if they implement IM otherwise (and override inputMethodQuery()). - // So for legacy reasons, we need to check by other means if IM is supported when - // Qt::ImEnabled is not implemented (the query returns an invalid QVariant). - // Since QWidget implements inputMethodQuery(), and return valid values for - // some of the IM properties, we cannot just query for Qt::ImQueryAll. - // Instead we assume that if a widget supports IM, it will implement - // Qt::ImSurroundingText (which is not implemented by QWidget). - const bool imEnabledFallback = inputMethodQuery(Qt::ImSurroundingText).isValid(); - v = QVariant(imEnabledFallback); + // if they implement IM otherwise (by overriding inputMethodQuery()). Instead + // they set the widget attribute Qt::WA_InputMethodEnabled. But this attribute + // will only be set if the widget supports IM _and_ is not read-only. So for + // read-only widgets, not all IM features will be supported when ImEnabled is + // not implemented explicitly (e.g selection handles for read-only widgets on iOS). + v = QVariant(testAttribute(Qt::WA_InputMethodEnabled)); } query->setValue(q, v); } diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index bd20f9963d..b87d7e09cc 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -1811,6 +1811,8 @@ QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property, QVariant arg { Q_D(const QLineEdit); switch(property) { + case Qt::ImEnabled: + return isEnabled(); case Qt::ImCursorRectangle: return d->cursorRect(); case Qt::ImAnchorRectangle: diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index 3fb8debaa5..cd9889e9ff 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -2206,6 +2206,8 @@ QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant a { Q_D(const QPlainTextEdit); switch (query) { + case Qt::ImEnabled: + return isEnabled(); case Qt::ImHints: case Qt::ImInputItemClipRectangle: return QWidget::inputMethodQuery(query); diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index de20e0120a..b3a8963431 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -1803,6 +1803,8 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume { Q_D(const QTextEdit); switch (query) { + case Qt::ImEnabled: + return isEnabled(); case Qt::ImHints: case Qt::ImInputItemClipRectangle: return QWidget::inputMethodQuery(query); |