diff options
author | Wang Chuan <ouchuanm@outlook.com> | 2021-02-07 11:05:23 +0800 |
---|---|---|
committer | Wang Chuan <ouchuanm@outlook.com> | 2021-02-09 20:00:59 +0800 |
commit | 13ae47d98057c2ddca8c865b845973d7e4c8dd8b (patch) | |
tree | 2fa1f61ac0e4d2e25e2cd011213ce16e2b860f90 /tests/auto/widgets/widgets/qplaintextedit | |
parent | 222c0ab081251f5249f31b6236ca7b912d303816 (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
Pick-to: 5.15 6.0 6.1
Change-Id: I45c686c7e09ca7b2944c36122e9157de0ec4f0e0
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/widgets/widgets/qplaintextedit')
-rw-r--r-- | tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp | 32 |
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" |