Details
-
Bug
-
Resolution: Incomplete
-
Not Evaluated
-
None
-
5.15.0, 5.15.1
-
None
Description
I am using TextEditor from the example provided with Qt https://doc.qt.io/qt-5/qtquickcontrols1-texteditor-example.html.
Here is the complete code https://code.qt.io/cgit/qt/qtquickcontrols.git/tree/examples/quickcontrols/controls/texteditor?h=5.15
I have created a custom method void DocumentHandler::setBackgroundColor(const QColor &color) to change the background color of the overall HTML document.
Now whenever I call a method to change the background color of QTextDocument using setDefaultStyleSheet, it is executed only once. ie, my document background changes only once. For the next calls, I can see the qDebug() printing correctly, but the setDefaultStyleSheet doesn't work. However, everything works perfectly with normal text, only not with _m_doc->toHtml()_.
Note: If I change _m_doc->setHtml("some random text")_, it works as required
This behavior is weird and not expected as it is breaking the continuity of the application
scopchanov did solve the problem with QString parsing. But the solution is quite delicate and may not work with all versions of Qt and with some other type of content.
Here is his solution https://stackoverflow.com/questions/64480690/why-qtextdocument-background-color-changes-only-once/64482549?noredirect=1#comment114022368_64482549
Attaching my code snippets