summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-06-22 13:58:38 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-07-01 10:47:17 +0200
commit3b123055755db3f11bd64b276a8f92fe39cf0e1e (patch)
tree5f1aad99e3f4e370f605a4b6cd90ba2ec1f79559 /tests
parent1ffe49dd199a6c502ed8c145e102de747284ba56 (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 Pick-to: 6.4 6.3 6.2 Change-Id: Ib391fd1daae92c4325e9ccb59730fbdd7c9328fc Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index f65882611b..397a1cf8df 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -369,6 +369,8 @@ private slots:
void focusProxy();
void focusProxyAndInputMethods();
+ void imEnabledNotImplemented();
+
#ifdef QT_BUILD_INTERNAL
void scrollWithoutBackingStore();
#endif
@@ -10982,6 +10984,35 @@ void tst_QWidget::focusProxyAndInputMethods()
QCOMPARE(qApp->focusObject(), toplevel.data());
}
+void tst_QWidget::imEnabledNotImplemented()
+{
+ // Check that a plain widget doesn't report that it supports IM. Only
+ // widgets that implements either Qt::ImEnabled, or the Qt4 backup
+ // solution, Qt::ImSurroundingText, should do so.
+ QWidget topLevel;
+ QWidget plain(&topLevel);
+ QLineEdit edit(&topLevel);
+ topLevel.show();
+
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
+ QApplication::setActiveWindow(&topLevel);
+ QVERIFY(QTest::qWaitForWindowActive(&topLevel));
+
+ // A plain widget should return false for ImEnabled
+ plain.setFocus(Qt::OtherFocusReason);
+ QCOMPARE(QApplication::focusWidget(), &plain);
+ QVariant imEnabled = QApplication::inputMethod()->queryFocusObject(Qt::ImEnabled, QVariant());
+ QVERIFY(imEnabled.isValid());
+ QVERIFY(!imEnabled.toBool());
+
+ // But a lineedit should return true
+ edit.setFocus(Qt::OtherFocusReason);
+ QCOMPARE(QApplication::focusWidget(), &edit);
+ imEnabled = QApplication::inputMethod()->queryFocusObject(Qt::ImEnabled, QVariant());
+ QVERIFY(imEnabled.isValid());
+ QVERIFY(imEnabled.toBool());
+}
+
#ifdef QT_BUILD_INTERNAL
class scrollWidgetWBS : public QWidget
{