From 19072a177bf72c28082a377f37ed19cbb06f9740 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 30 Nov 2021 21:23:13 +0100 Subject: [PATCH] QPageLayout: do not calculate an invalid margin A default constructed QPageLayout has an invalid QPageSize. When asking for its size, an invalid QSize is returned (-1, -1). This size is then used to calculate the maximum margins the page layout can have, resulting in negative margins. I'm not sure if that makes sense for QPageLayout (in principle, a negative margin is acceptable, meaning to "grow" the size), but then this margin is passed as an upper bound to a series of qBound calls in QPageLayoutPrivate::clampMargins. To fix this, change the calculations of the maximum margins by using a lower bound of 0. Change-Id: I429104acfb2296d9eb1ee54c113e9d7e22d9b6ab Reviewed-by: Volker Hilsheimer --- src/gui/painting/qpagelayout.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/painting/qpagelayout.cpp b/src/gui/painting/qpagelayout.cpp index def9751aa66..ddd5c9a15b4 100644 --- a/src/gui/painting/qpagelayout.cpp +++ b/src/gui/painting/qpagelayout.cpp @@ -231,10 +231,10 @@ QMargins QPageLayoutPrivate::marginsPixels(int resolution) const void QPageLayoutPrivate::setDefaultMargins(const QMarginsF &minMargins) { m_minMargins = minMargins; - m_maxMargins = QMarginsF(m_fullSize.width() - m_minMargins.right(), - m_fullSize.height() - m_minMargins.bottom(), - m_fullSize.width() - m_minMargins.left(), - m_fullSize.height() - m_minMargins.top()); + m_maxMargins = QMarginsF(qMax(m_fullSize.width() - m_minMargins.right(), qreal(0)), + qMax(m_fullSize.height() - m_minMargins.bottom(), qreal(0)), + qMax(m_fullSize.width() - m_minMargins.left(), qreal(0)), + qMax(m_fullSize.height() - m_minMargins.top(), qreal(0))); if (m_mode == QPageLayout::StandardMode) clampMargins(m_margins); }