summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWang Chuan <ouchuanm@outlook.com>2021-02-07 11:05:23 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-09 17:52:06 +0000
commitbbdcc86c52d806ab45fabf167526f9dcec291648 (patch)
treee131e77c82c780a75e1b4f714b48ac32c0bb3e72 /tests
parent30001fdaf90a22d575c2f4def5a89789508c30aa (diff)
QPlainTextEdit: adjust scroll bars when showing up
The text of QPlainTextEdit might change when it is invisible, so an adjustment of scroll bars is needed when the QPlainTextEdit showing up, otherwise the range of scroll bars might be incorrect. Fixes: QTBUG-77937 Change-Id: I45c686c7e09ca7b2944c36122e9157de0ec4f0e0 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit 13ae47d98057c2ddca8c865b845973d7e4c8dd8b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
index 0cffe14ee4..297eb5ec51 100644
--- a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
+++ b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
@@ -153,6 +153,7 @@ private slots:
#ifndef QT_NO_CLIPBOARD
void updateCursorPositionAfterEdit();
#endif
+ void appendTextWhenInvisible();
private:
void createSelection();
@@ -1805,5 +1806,36 @@ void tst_QPlainTextEdit::updateCursorPositionAfterEdit()
}
#endif
+void tst_QPlainTextEdit::appendTextWhenInvisible()
+{
+ QWidget window;
+ window.resize(640, 480);
+
+ QPlainTextEdit *plainTextEdit = new QPlainTextEdit(&window);
+ plainTextEdit->resize(320, 240);
+
+ window.show();
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+
+ // this should be long enough to let vertical scroll bar show up
+ const QString baseText("text\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\ntext");
+ const QString textToAppend("aaa");
+
+ plainTextEdit->setPlainText(baseText + "\n" + textToAppend);
+ const auto maxAfterSet = plainTextEdit->verticalScrollBar()->maximum();
+ // make sure the vertical scroll bar is visible
+ QVERIFY(maxAfterSet != 0);
+
+ plainTextEdit->clear();
+ plainTextEdit->setPlainText(baseText);
+ plainTextEdit->hide();
+ plainTextEdit->appendPlainText(textToAppend);
+ plainTextEdit->show();
+ const auto maxAfterAppend = plainTextEdit->verticalScrollBar()->maximum();
+ QVERIFY(maxAfterAppend != 0);
+
+ QCOMPARE(maxAfterAppend, maxAfterSet);
+}
+
QTEST_MAIN(tst_QPlainTextEdit)
#include "tst_qplaintextedit.moc"