diff options
author | Andreas Aardal Hanssen <andrhans@cisco.com> | 2012-04-08 11:58:30 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-12 04:35:22 +0200 |
commit | a9cda515177db1615f8d47becf2aa781f26955ae (patch) | |
tree | 2d0e872b7338c89d63b80471c02b059530759bfd | |
parent | c7da50ef8cf30558537425918cf03f5e72c680c1 (diff) |
Fixes a regression; missing cursor blink when input mask is set.
I can't say for sure why q*linecontrol passes an empty rect to
the updateNeeded() signal when an input mask is set; presumably
the empty rect at some point has meant "full update", but there
are a few problems with this. Surely a full update is wrong,
even if the semantics have been lost in translation somewhere
(likely the qlinecontrol refactoring). This fix ensures
that empty rects from updateNeeded() are interpreted as a request
to update the whole widget. A further improvement would be to
ensure the line control doesn't request a full update when an
input mask is set. The cursor is usually wider when a mask is
set but because of QLineEdit::paintEvent()'s implementation,
there is currently a mismatch between the cursor width as seen
by q*linecontrol and what is actually drawn, which causes
rendering artifacts if updateNeeded() sends the cursorRect().
Since QLineEdit and Q*LineControl aren't actively developed, it's
best to keep this fix minimal, although the performance cost of
updating the whole line edit when an input mask is set is
unfortunate.
Task-number: QTBUG-7174
Change-Id: Ie51e015d760915e07b0220b770f04fc958d93a12
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
-rw-r--r-- | src/widgets/widgets/qlineedit_p.cpp | 3 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | 25 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index 6cee96e717..d1c374a6ca 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -62,9 +62,10 @@ const int QLineEditPrivate::horizontalMargin(2); QRect QLineEditPrivate::adjustedControlRect(const QRect &rect) const { + QRect widgetRect = !rect.isEmpty() ? rect : q_func()->rect(); QRect cr = adjustedContentsRect(); int cix = cr.x() - hscroll + horizontalMargin; - return rect.translated(QPoint(cix, vscroll)); + return widgetRect.translated(QPoint(cix, vscroll)); } int QLineEditPrivate::xToPos(int x, QTextLine::CursorPosition betweenOrOn) const diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 06bf929e4b..22e05a8871 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -271,6 +271,7 @@ private slots: void taskQTBUG_7395_readOnlyShortcut(); void QTBUG697_paletteCurrentColorGroup(); void QTBUG13520_textNotVisible(); + void QTBUG7174_inputMaskCursorBlink(); void bidiVisualMovement_data(); void bidiVisualMovement(); @@ -3693,6 +3694,30 @@ void tst_QLineEdit::QTBUG13520_textNotVisible() } +class UpdateRegionLineEdit : public QLineEdit +{ +public: + QRegion updateRegion; +protected: + void paintEvent(QPaintEvent *event) + { + updateRegion = event->region(); + } +}; + +void tst_QLineEdit::QTBUG7174_inputMaskCursorBlink() +{ + UpdateRegionLineEdit edit; + edit.setInputMask(QLatin1String("AAAA")); + edit.setFocus(); + edit.setText(QLatin1String("AAAA")); + edit.show(); + QRect cursorRect = edit.inputMethodQuery(Qt::ImMicroFocus).toRect(); + QTest::qWaitForWindowShown(&edit); + edit.updateRegion = QRegion(); + QTest::qWait(QApplication::cursorFlashTime()); + QVERIFY(edit.updateRegion.contains(cursorRect)); +} void tst_QLineEdit::bidiVisualMovement_data() { |