summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-11-30 21:23:13 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-12-06 12:28:41 +0100
commit19072a177bf72c28082a377f37ed19cbb06f9740 (patch)
treea101e77d97a2ca2cd5845a6dce4508e4e1a8ffdf /src/gui
parent212b7614e1afce5a3cfc03b481784ff1d2a1aa01 (diff)
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 <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/painting/qpagelayout.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/gui/painting/qpagelayout.cpp b/src/gui/painting/qpagelayout.cpp
index def9751aa6..ddd5c9a15b 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);
}