diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 7e9dfbe3000..87c524ffc16 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1652,7 +1652,7 @@ void QTextLine::setNumColumns(int numColumns) void QTextLine::setNumColumns(int numColumns, qreal alignmentWidth) { QScriptLine &line = eng->lines[index]; - line.width = QFixed::fromReal(alignmentWidth); + line.width = QFixed::fromReal(qBound(0.0, alignmentWidth, qreal(QFIXED_MAX))); line.length = 0; line.textWidth = 0; layout_helper(numColumns); diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index bea2556e68e..a0baa43cbcb 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -2737,13 +2737,25 @@ void tst_QTextLayout::min_maximumWidth() void tst_QTextLayout::negativeLineWidth() { - QTextLayout layout; - layout.setText("Foo bar"); - layout.beginLayout(); - QTextLine line = layout.createLine(); - line.setLineWidth(-1); - QVERIFY(line.textLength() > 0); - layout.endLayout(); + { + QTextLayout layout; + layout.setText("Foo bar"); + layout.beginLayout(); + QTextLine line = layout.createLine(); + line.setLineWidth(-1); + QVERIFY(line.textLength() > 0); + layout.endLayout(); + } + + { + QTextLayout layout; + layout.setText("Foo bar"); + layout.beginLayout(); + QTextLine line = layout.createLine(); + line.setNumColumns(2, -1); + QVERIFY(line.textLength() > 0); + layout.endLayout(); + } } QTEST_MAIN(tst_QTextLayout)