summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwidget.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-06-22 13:58:38 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-07-01 12:09:36 +0000
commitbe918dd5e7436b535ae80caa5413dba1204ce6f7 (patch)
tree60d9156e66475b7d9ff82df9f263f8a956b45d03 /src/widgets/kernel/qwidget.cpp
parent18c71a29c878b7a720461d36ccd131f6ecb7e568 (diff)
IM: Don't let all widgets support IM by default
A new property Qt::ImEnabled was added in Qt 5.3. Since the already existing widgets with IM support (3rd party included) didn't implement this property, QWidget got the fall back logic that if a widget was queried for Qt::ImEnabled, and the returned QVariant was invalid (the widget didn't implement it), we would, for backwards compatibility with Qt 4, return "true" (meaning that the widget supports IM). But a side effect from this fallback logic, is that now any widget that doesn't implement ImEnabled (or input methods at all) report that they support IM. This will confuse platforms like iOS, which uses ImEnabled to decide if the input panel should show, and if text selection tools should be enabled. The result is therefore that if you click on a QPushButton, the input panel will open. This patch will implement a more careful strategy to check if a widget implements IM, if ImEnabled is missing. Rather than saying that all widgets that don't implement ImEnabled supports IM, we now require that the widget also returns a valid QVariant for Qt::ImSurroundingText. We assume then, that a widget that doesn't do so will anyway not be in need of input method support from the platform. Fixes: QTBUG-104527 Change-Id: Ib391fd1daae92c4325e9ccb59730fbdd7c9328fc Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit 3b123055755db3f11bd64b276a8f92fe39cf0e1e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r--src/widgets/kernel/qwidget.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index cf32ff6c93..1160471194 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -8896,8 +8896,18 @@ bool QWidget::event(QEvent *event)
Qt::InputMethodQuery q = (Qt::InputMethodQuery)(int)(queries & (1<<i));
if (q) {
QVariant v = inputMethodQuery(q);
- if (q == Qt::ImEnabled && !v.isValid() && isEnabled())
- v = QVariant(true); // special case for Qt4 compatibility
+ 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);
+ }
query->setValue(q, v);
}
}