diff --git a/examples/widgets/richtext/textedit/example.html b/examples/widgets/richtext/textedit/example.html index 99090a697f..ca3dce23cc 100644 --- a/examples/widgets/richtext/textedit/example.html +++ b/examples/widgets/richtext/textedit/example.html @@ -1,6 +1,8 @@ -
The QTextEdit widget is an advanced editor that supports formatted rich text. It can be used to display HTML and other rich document formats. Internally, QTextEdit uses the QTextDocument class to describe both the high-level structure of each document and the low-level formatting of paragraphs.
If you are viewing this document in the textedit example, you can edit this document to explore Qt's rich text editing features. We have included some comments in each of the following sections to encourage you to experiment.
@@ -27,6 +29,9 @@ p, li { white-space: pre-wrap; }Inline images are treated like ordinary ranges of characters in the text editor, so they flow with the surrounding text. Images can also be selected in the same way as text, making it easy to cut, copy, and paste them.
Try to select this image by clicking and dragging over it with the mouse, or use the text cursor to select it by holding down Shift and using the arrow keys. You can then cut or copy it, and paste it into different parts of this document.
Here is an example:
+QTextEdit can arrange and format tables, supporting features such as row and column spans, text formatting within cells, and size constraints for columns.
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index d3bec57bd4..68cdbc092e 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2359,6 +2359,7 @@ QString QTextHtmlExporter::toHtml(ExportMode mode) html += QString::fromLatin1("Blah
" - ""); + QString expectedHtml = htmlHead; + expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"#0000ff\""); + expectedHtml += "Blah
" + + htmlTail; - expectedHtml = expectedHtml.arg(defaultFont.family()) - .arg(cssFontSizeString(defaultFont)) - .arg(defaultFont.weight()) - .arg((defaultFont.italic() ? "italic" : "normal")); + writeActualAndExpected(QTest::currentDataTag(), doc.toHtml(), expectedHtml); QCOMPARE(doc.toHtml(), expectedHtml); } @@ -1932,20 +1937,12 @@ void tst_QTextDocument::toHtmlBodyBgColorRgba() fmt.setBackground(QColor(255, 0, 0, 51)); doc.rootFrame()->setFrameFormat(fmt); - QString expectedHtml("\n" - "" - "\n" - "Blah
" - ""); + QString expectedHtml = htmlHead; + expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"rgba(255,0,0,0.2)\""); + expectedHtml += "Blah
" + + htmlTail; - expectedHtml = expectedHtml.arg(defaultFont.family()) - .arg(cssFontSizeString(defaultFont)) - .arg(defaultFont.weight()) - .arg((defaultFont.italic() ? "italic" : "normal")); + writeActualAndExpected(QTest::currentDataTag(), doc.toHtml(), expectedHtml); QCOMPARE(doc.toHtml(), expectedHtml); } @@ -1960,20 +1957,12 @@ void tst_QTextDocument::toHtmlBodyBgColorTransparent() fmt.setBackground(QColor(255, 0, 0, 0)); doc.rootFrame()->setFrameFormat(fmt); - QString expectedHtml("\n" - "" - "\n" - "Blah
" - ""); + QString expectedHtml = htmlHead; + expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"transparent\""); + expectedHtml += "Blah
" + + htmlTail; - expectedHtml = expectedHtml.arg(defaultFont.family()) - .arg(cssFontSizeString(defaultFont)) - .arg(defaultFont.weight()) - .arg((defaultFont.italic() ? "italic" : "normal")); + writeActualAndExpected(QTest::currentDataTag(), doc.toHtml(), expectedHtml); QCOMPARE(doc.toHtml(), expectedHtml); } @@ -2034,21 +2023,13 @@ void tst_QTextDocument::toHtmlDefaultFontSpacingProperties() fnt.setWordSpacing(15); doc.setDefaultFont(fnt); - QString expectedOutput = QString("\n" - "" - "" - "\n" - "Blah
" - ""); - expectedOutput = expectedOutput.arg(defaultFont.family()) - .arg(cssFontSizeString(defaultFont)) - .arg(defaultFont.weight()) - .arg((defaultFont.italic() ? "italic" : "normal")); + QString expectedOutput = htmlHead; + expectedOutput.insert(htmlHead.length() - 3, " letter-spacing:13px; word-spacing:15px;"); + expectedOutput += + "Blah
" + + htmlTail; + + writeActualAndExpected(QTest::currentTestFunction(), doc.toHtml(), expectedOutput); QCOMPARE(doc.toHtml(), expectedOutput); } @@ -2062,23 +2043,13 @@ void tst_QTextDocument::toHtmlTextDecorationUnderline() fnt.setUnderline(true); doc.setDefaultFont(fnt); - QString expectedOutput = - QString("\n" - "" - "" - "\n" - "Some text
" - ""); + QString expectedOutput = htmlHead; + expectedOutput.insert(htmlHead.length() - 3, " text-decoration: underline;"); + expectedOutput += + "Some text
" + + htmlTail; - expectedOutput = expectedOutput.arg(doc.defaultFont().family()) - .arg(cssFontSizeString(doc.defaultFont())) - .arg(doc.defaultFont().weight()) - .arg((doc.defaultFont().italic() ? "italic" : "normal")); + writeActualAndExpected("toHtmlTextDecorationUnderline1", doc.toHtml(), expectedOutput); QCOMPARE(doc.toHtml(), expectedOutput); @@ -2087,26 +2058,17 @@ void tst_QTextDocument::toHtmlTextDecorationUnderline() cursor.select(QTextCursor::Document); cursor.mergeCharFormat(format); - QString expectedOutput2 = - QString("\n" - "" - "" - "\n" - "" - "Some text
" - ""); + expectedOutput = htmlHead; + expectedOutput.insert(htmlHead.length() - 3, " text-decoration: underline;"); + expectedOutput += + "" + "Some text
" + + htmlTail; - expectedOutput2 = expectedOutput2.arg(doc.defaultFont().family()) - .arg(cssFontSizeString(doc.defaultFont())) - .arg(doc.defaultFont().weight()) - .arg((doc.defaultFont().italic() ? "italic" : "normal")); + writeActualAndExpected("toHtmlTextDecorationUnderline2", doc.toHtml(), expectedOutput); - QCOMPARE(doc.toHtml(), expectedOutput2); + QCOMPARE(doc.toHtml(), expectedOutput); } void tst_QTextDocument::capitalizationHtmlInExport() @@ -2985,21 +2947,11 @@ const QString backgroundImage_html("
void tst_QTextDocument::backgroundImage_checkExpectedHtml(const QTextDocument &doc)
{
- QString expectedHtml("\n"
- ""
- "\n"
+ QString expectedHtml = htmlHead +
"
|