Respect contents margins when calculating the size hint

Without this part of the calendar widget get cut off when put
in a layout and the contentsMargins are non zero.

Task-number: QTBUG-40352
Change-Id: I9ce90476c59c270d92e876a5dc81ea8ce325848c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
This commit is contained in:
Lars Knoll 2014-09-10 08:31:35 +02:00 committed by Jan Arve Sæther
parent c5bc66df2f
commit bd4a19963e
2 changed files with 13 additions and 0 deletions

View File

@ -2247,6 +2247,9 @@ QSize QCalendarWidget::minimumSizeHint() const
w *= cols;
w = qMax(headerSize.width(), w);
h = (h * rows) + headerSize.height();
QMargins cm = contentsMargins();
w += cm.left() + cm.right();
h += cm.top() + cm.bottom();
d->cachedSizeHint = QSize(w, h);
return d->cachedSizeHint;
}

View File

@ -67,6 +67,8 @@ private slots:
void showPrevNext();
void firstDayOfWeek();
void contentsMargins();
};
// Testing get/set functions
@ -391,5 +393,13 @@ void tst_QCalendarWidget::firstDayOfWeek()
QCOMPARE(calendar.firstDayOfWeek(), germanLocale.firstDayOfWeek());
}
void tst_QCalendarWidget::contentsMargins()
{
QCalendarWidget calendar1;
QCalendarWidget calendar2;
calendar2.setContentsMargins(10, 5, 20, 30);
QCOMPARE(calendar1.minimumSizeHint() + QSize(30, 35), calendar2.minimumSizeHint());
}
QTEST_MAIN(tst_QCalendarWidget)
#include "tst_qcalendarwidget.moc"