QPlainTextEdit: update scrollbars after setting center on scroll

Fixes: QTBUG-64730
Change-Id: I6ff7b10eb209a407c99529a09226cd97f9b6e9f8
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
This commit is contained in:
David Schulz 2017-11-24 13:22:49 +01:00
parent c4a524f3a1
commit 706db17d9a
2 changed files with 19 additions and 0 deletions

View File

@ -2892,6 +2892,7 @@ void QPlainTextEdit::setCenterOnScroll(bool enabled)
if (enabled == d->centerOnScroll)
return;
d->centerOnScroll = enabled;
d->_q_adjustScrollbars();
}

View File

@ -147,6 +147,9 @@ private slots:
void contextMenu();
#endif
void inputMethodCursorRect();
#if QT_CONFIG(scrollbar)
void updateAfterChangeCenterOnScroll();
#endif
private:
void createSelection();
@ -1727,5 +1730,20 @@ void tst_QPlainTextEdit::inputMethodCursorRect()
QCOMPARE(cursorRectV.toRect(), cursorRect.toRect());
}
#if QT_CONFIG(scrollbar)
// QTBUG-64730: Verify that the scrollbar is updated after center on scroll was set
void tst_QPlainTextEdit::updateAfterChangeCenterOnScroll()
{
ed->setPlainText("Line1\nLine2Line3\nLine3");
ed->show();
ed->setCenterOnScroll(true);
const int maxWithCenterOnScroll = ed->verticalScrollBar()->maximum();
ed->setCenterOnScroll(false);
const int maxWithoutCenterOnScroll = ed->verticalScrollBar()->maximum();
QVERIFY(maxWithCenterOnScroll > maxWithoutCenterOnScroll);
}
#endif
QTEST_MAIN(tst_QPlainTextEdit)
#include "tst_qplaintextedit.moc"