summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
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
commitcc5a1473f1fb22321f01b9955225eea1df54f417 (patch)
tree6d582f3da3acca7bbda1b71508bfba24ae7f8e84 /tests/auto/widgets
parent56981d3073355c80437786f5d479043e1471a571 (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/auto/widgets')
-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 831612b910..24aa755ad8 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"