From bd288ab2554e500ddfee806a39f00ca3ef4ddcbc Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 9 Apr 2025 20:40:03 +0200 Subject: [PATCH] QDateTimeEdit: Unify height of QDateTimeEdit After 0a1c1711453697a88eee7fdb6f4cf082bfd433e2 a QDateTimeEdit with and without a popup has different heights in some styles. Fixing the styles may break existing layouts so we only get the needed width when the popup is enable from CT_ComboBox and let the height being calculated by CT_SpinBox to make sure both variants have the same height. Pick-to: 6.8 Fixes: QTBUG-135029 Task-number: QTBUG-11967 Change-Id: I01c6f598d34a0b73125e60650c61a84b27d79ac8 Reviewed-by: Volker Hilsheimer (cherry picked from commit 105ddadffeecf2370785ccd9bffde42fdbe25d1c) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/widgets/qdatetimeedit.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index ccfbc635dca..1c3118fe785 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -1092,15 +1092,15 @@ QSize QDateTimeEdit::sizeHint() const w += 2; // cursor blinking space QSize hint(w, h); + QStyleOptionSpinBox opt; + initStyleOption(&opt); + d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this); if (d->calendarPopupEnabled()) { - QStyleOptionComboBox opt; - opt.initFrom(this); - opt.frame = d->frame; - d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_ComboBox, &opt, hint, this); - } else { - QStyleOptionSpinBox opt; - initStyleOption(&opt); - d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this); + QStyleOptionComboBox optCbx; + optCbx.initFrom(this); + optCbx.frame = d->frame; + d->cachedSizeHint.rwidth() = + style()->sizeFromContents(QStyle::CT_ComboBox, &optCbx, hint, this).width(); } d->cachedMinimumSizeHint = d->cachedSizeHint;