summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2014-09-25 17:23:15 +0200
committerKonstantin Ritt <ritt.ks@gmail.com>2014-11-27 04:19:05 +0100
commit2d0b20ef9218aa40218ab6c872a60c28e56b1ac2 (patch)
treebfed769d44ca06aa350a6e30de0335ce06105d53
parentb9d98c10bdc3c8e6330e84cca48ea302e8cd61c3 (diff)
QLineEdit: take text margins into account in minimumSizeHint().
sizeHint() did it exactly like this, but minimumSizeHint() didn't, which made it too small. Didn't affect the actual size in most cases since the vertical size policy is fixed, so sizeHint() is called instead. But when writing a subclass, if one re-implements sizeHint() by calling the QLineEdit's minimumSizeHint(), it would then be wrong, when text margins are used. Change-Id: I29ae8dcab00842b3b5ca534cdb250efc0b496f45 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
-rw-r--r--src/widgets/widgets/qlineedit.cpp5
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp10
2 files changed, 14 insertions, 1 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index cf294e3c34..bd8dd783ff 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -712,8 +712,11 @@ QSize QLineEdit::minimumSizeHint() const
ensurePolished();
QFontMetrics fm = fontMetrics();
int h = fm.height() + qMax(2*d->verticalMargin, fm.leading())
+ + d->topTextMargin + d->bottomTextMargin
+ d->topmargin + d->bottommargin;
- int w = fm.maxWidth() + d->leftmargin + d->rightmargin;
+ int w = fm.maxWidth()
+ + d->effectiveLeftTextMargin() + d->effectiveRightTextMargin()
+ + d->leftmargin + d->rightmargin;
QStyleOptionFrame opt;
initStyleOption(&opt);
return (style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h).
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index 78fa0b4928..bf4d1f2ebd 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -3384,10 +3384,20 @@ void tst_QLineEdit::textMargin()
testWidget.setCursorPosition(6);
QSize sizeHint = testWidget.sizeHint();
+ QSize minSizeHint = testWidget.minimumSizeHint();
testWidget.setTextMargins(left, top, right, bottom);
+
sizeHint.setWidth(sizeHint.width() + left + right);
sizeHint.setHeight(sizeHint.height() + top +bottom);
QCOMPARE(testWidget.sizeHint(), sizeHint);
+
+ if (minSizeHint.width() > -1) {
+ minSizeHint.setWidth(minSizeHint.width() + left + right);
+ minSizeHint.setHeight(minSizeHint.height() + top + bottom);
+ QCOMPARE(testWidget.minimumSizeHint(), minSizeHint);
+ }
+
+
testWidget.setFrame(false);
centerOnScreen(&tlw);
tlw.show();