aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick
diff options
context:
space:
mode:
authorWang Chuan <ouchuanm@outlook.com>2021-04-05 11:41:48 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-04-16 22:47:18 +0000
commit84fd42a91314b04448931dd1473eef7a9b5c3931 (patch)
tree089ba70bb456e3ab43ed82676af0b31f93ad60cd /tests/auto/quick
parent295e30b4ea2dd1ff269bd05a66fdf56083b3f89b (diff)
QQuickTextInput: update cursor rectangle after padding changed
The position of cursor delegate needs to be updated when we change padding, otherwise it will be in a wrong position. Fixes: QTBUG-91867 Change-Id: I89ca84fe893ebf517ab67890196eede14a4055d7 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit d98694c4023881673259ba040c10df7e71ec3d37) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r--tests/auto/quick/qquicktextinput/data/checkCursorDelegateWhenPaddingChanged.qml16
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp30
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextinput/data/checkCursorDelegateWhenPaddingChanged.qml b/tests/auto/quick/qquicktextinput/data/checkCursorDelegateWhenPaddingChanged.qml
new file mode 100644
index 0000000000..e6f07b4687
--- /dev/null
+++ b/tests/auto/quick/qquicktextinput/data/checkCursorDelegateWhenPaddingChanged.qml
@@ -0,0 +1,16 @@
+import QtQuick 2.12
+
+Rectangle {
+ width: 200
+ height: 200
+ TextInput {
+ objectName: "textInput"
+ leftPadding: 10
+ focus: true
+ cursorDelegate: Rectangle {
+ objectName: "cursorDelegate"
+ width: 5
+ color: "red"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
index d0e5425c0f..7d4c9ec553 100644
--- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
+++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
@@ -238,6 +238,7 @@ private slots:
void QTBUG_51115_readOnlyResetsSelection();
void QTBUG_77814_InsertRemoveNoSelection();
+ void checkCursorDelegateWhenPaddingChanged();
private:
void simulateKeys(QWindow *window, const QList<Key> &keys);
#if QT_CONFIG(shortcut)
@@ -7023,6 +7024,35 @@ void tst_qquicktextinput::QTBUG_77814_InsertRemoveNoSelection()
QCOMPARE(textInput->selectedText(), QString());
}
+void tst_qquicktextinput::checkCursorDelegateWhenPaddingChanged()
+{
+ QQuickView view;
+ view.setSource(testFileUrl("checkCursorDelegateWhenPaddingChanged.qml"));
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
+ QQuickTextInput *textInput = view.rootObject()->findChild<QQuickTextInput *>("textInput");
+ QVERIFY(textInput);
+
+ QQuickItem *cursorDelegate = textInput->findChild<QQuickItem *>("cursorDelegate");
+ QVERIFY(cursorDelegate);
+
+ QCOMPARE(cursorDelegate->x(), textInput->leftPadding());
+ QCOMPARE(cursorDelegate->y(), textInput->topPadding());
+
+ textInput->setPadding(5);
+ QCOMPARE(cursorDelegate->x(), textInput->leftPadding());
+ QCOMPARE(cursorDelegate->y(), textInput->topPadding());
+
+ textInput->setTopPadding(10);
+ QCOMPARE(cursorDelegate->x(), textInput->leftPadding());
+ QCOMPARE(cursorDelegate->y(), textInput->topPadding());
+
+ textInput->setLeftPadding(10);
+ QCOMPARE(cursorDelegate->x(), textInput->leftPadding());
+ QCOMPARE(cursorDelegate->y(), textInput->topPadding());
+}
+
QTEST_MAIN(tst_qquicktextinput)
#include "tst_qquicktextinput.moc"