diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index a242d5e6459..2a812ad9991 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -1032,8 +1032,11 @@ void QTextHtmlParserNode::initializeProperties(const QTextHtmlParserNode *parent // we don't paint per-row background colors, yet. so as an // exception inherit the background color here // we also inherit the background between inline elements + // we also inherit from non-body block elements since we merge them together if ((parent->id != Html_tr || !isTableCell()) - && (displayMode != QTextHtmlElement::DisplayInline || parent->displayMode != QTextHtmlElement::DisplayInline)) { + && (displayMode != QTextHtmlElement::DisplayInline || parent->displayMode != QTextHtmlElement::DisplayInline) + && (parent->id == Html_body || displayMode != QTextHtmlElement::DisplayBlock || parent->displayMode != QTextHtmlElement::DisplayBlock) + ) { charFormat.clearProperty(QTextFormat::BackgroundBrush); } diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp index a7408fcc8eb..08ec74b5d44 100644 --- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp +++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp @@ -142,6 +142,7 @@ private slots: void html_doNotInheritBackground(); void html_inheritBackgroundToInlineElements(); void html_doNotInheritBackgroundFromBlockElements(); + void html_inheritBackgroundFromBlockElements(); void html_nobr(); void fromPlainText(); void fromPlainText2(); @@ -2070,7 +2071,7 @@ void tst_QTextDocumentFragment::html_inheritBackgroundToInlineElements() void tst_QTextDocumentFragment::html_doNotInheritBackgroundFromBlockElements() { - const char html[] = "

Foo"; + const char html[] = "

Foo

"; doc->setHtml(html); int fragmentCount = 0; @@ -2088,6 +2089,31 @@ void tst_QTextDocumentFragment::html_doNotInheritBackgroundFromBlockElements() QCOMPARE(fragmentCount, 1); } + +void tst_QTextDocumentFragment::html_inheritBackgroundFromBlockElements() +{ + const char html[] = "

Foo

Bar

"; + doc->setHtml(html); + + int fragmentCount = 0; + + QTextBlock block = doc->begin(); + for (QTextBlock::Iterator it = block.begin(); + !it.atEnd(); ++it, ++fragmentCount) { + + const QTextFragment fragment = it.fragment(); + if (fragmentCount == 0) { + QCOMPARE(fragment.text(), QString("Foo")); + QVERIFY(fragment.charFormat().hasProperty(QTextFormat::BackgroundBrush)); + } else { + QCOMPARE(fragment.text(), QString("Bar")); + QVERIFY(fragment.charFormat().hasProperty(QTextFormat::BackgroundBrush)); + } + } + + QCOMPARE(fragmentCount, 1); +} + void tst_QTextDocumentFragment::html_nobr() { const QString input = "Blah Foo Bar";