Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-87806

QTextDocument background color changes only once using setDefaultStyleSheet

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 5.15.0, 5.15.1
    • GUI: Text handling
    • None
    • All

    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

       

      Attachments

        1. DocumentHandler.cpp
          0.7 kB
        2. test.qml
          0.9 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            chilarai chilarai mushahary
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes