From 7e9ac1bab3527de054552ff3f38ab70945f49512 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 9 Sep 2010 14:58:38 +0200 Subject: Fixed the scrolling of text in QLineEdit with right alignment The scrolling internal member was not changed in cas the text was bigger than the lineedit. Task-number: QTBUG-13520 Reviewed-by: gabi --- src/gui/widgets/qlineedit.cpp | 4 ++++ tests/auto/qlineedit/tst_qlineedit.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp index 981e934..caaef68 100644 --- a/src/gui/widgets/qlineedit.cpp +++ b/src/gui/widgets/qlineedit.cpp @@ -1929,7 +1929,11 @@ void QLineEdit::paintEvent(QPaintEvent *) // text doesn't fit, text document is to the left of lineRect; align // right d->hscroll = widthUsed - lineRect.width() + 1; + } else { + //in case the text is bigger than the lineedit, the hscroll can never be negative + d->hscroll = qMax(0, d->hscroll); } + // the y offset is there to keep the baseline constant in case we have script changes in the text. QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent()); diff --git a/tests/auto/qlineedit/tst_qlineedit.cpp b/tests/auto/qlineedit/tst_qlineedit.cpp index 717b32d..bfa9406 100644 --- a/tests/auto/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/qlineedit/tst_qlineedit.cpp @@ -275,6 +275,7 @@ private slots: #endif void taskQTBUG_7395_readOnlyShortcut(); void QTBUG697_paletteCurrentColorGroup(); + void QTBUG13520_textNotVisible(); #ifdef QT3_SUPPORT void validateAndSet_data(); @@ -3034,6 +3035,8 @@ public: }; State state; + + friend class tst_QLineEdit; }; Q_DECLARE_METATYPE(LineEdit::State); @@ -3741,5 +3744,21 @@ void tst_QLineEdit::QTBUG697_paletteCurrentColorGroup() QCOMPARE(img.pixel(10, le.height()/2), QColor(Qt::red).rgb()); } +void tst_QLineEdit::QTBUG13520_textNotVisible() +{ + LineEdit le; + le.setAlignment( Qt::AlignRight | Qt::AlignVCenter); + le.show(); + QTest::qWaitForWindowShown(&le); + le.setText("01-ST16-01SIL-MPL001wfgsdfgsdgsdfgsdfgsdfgsdfgsdfg"); + le.setCursorPosition(0); + QTest::qWait(100); //just make sure we get he lineedit correcly painted + + QVERIFY(le.cursorRect().center().x() < le.width() / 2); + + +} + + QTEST_MAIN(tst_QLineEdit) #include "tst_qlineedit.moc" -- cgit v0.12