From f6e3ea4f7335a5c840a4dfc066ea4f3874fac38e Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 22 Dec 2022 11:36:49 +0100 Subject: [PATCH] Fix assert when resizing text table with percentage widths Since Qt 6.3.x, qBound() has started asserting that max > min. This caused a crash in the QTextDocumentLayout code for assigning widths to table columns that were sized using percentages, which depended on previous qBound() behavior of just snapping to the minimum size if max < min. There are some specific conditions for this to happen: First of all, the available width in the table must be too small to fit all minimum widths (which is calculated based on content). In addition, the requested widths have to be given as percentages of the table width, and these have to add to something lower than 100%. With these conditions, you may get a case where the calculated percentage width of a column is larger than the minimum width, but lower than the remaining width in the table, causing the assert in qBound(). We simply accept the minimum width as the rule in these cases, which matches behavior without the assert and which looks correct when resizing the window to be smaller than the table. Fixes: QTBUG-108183 Change-Id: I16d18dd9b2e7a77fe86d1a353b426075b5050b8e Reviewed-by: Qt CI Bot Reviewed-by: Lars Knoll (cherry picked from commit 84a68ef75ce8a8e5b90d799c90905cc998c7c2f6) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/qtextdocumentlayout.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index c95ec4c6868..91ca58a50d7 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -2553,8 +2553,9 @@ recalc_minmax_widths: const QFixed allottedPercentage = QFixed::fromReal(columnWidthConstraints.at(i).rawValue()); const QFixed percentWidth = totalPercentagedWidth * allottedPercentage / totalPercentage; - if (percentWidth >= td->minWidths.at(i)) { - td->widths[i] = qBound(td->minWidths.at(i), percentWidth, remainingWidth - remainingMinWidths); + QFixed maxWidth = remainingWidth - remainingMinWidths; + if (percentWidth >= td->minWidths.at(i) && maxWidth > td->minWidths.at(i)) { + td->widths[i] = qBound(td->minWidths.at(i), percentWidth, maxWidth); } else { td->widths[i] = td->minWidths.at(i); }