Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Setting QTextBrowser text background color



  • Is it possible to set individual characters background color in QTextBrowser or QTextEdit ?

    I don't mean font color of text but different colored background squares under individual characters.



  • @Q139
    Untested, but I assume since both of those accept HTML (you're prepared to use that, right?) you can use stylesheet {background-color: ...} around each individual character? Say like:

    <span style='background-color: red;'>R</span><span style='background-color: green;'>G</span><span style='background-color: blue;'>B</span>...
    

    Unless someone else knows better/a better way?



  • @JonB Thanks for correct syntax , solved.
    In syntax background without -color also works.



  • @Q139
    Assuming QSS is approximately similar to HTML CSS, background does a lot more than just set the color: https://developer.mozilla.org/en-US/docs/Web/CSS/background. It so happens that background: green; sets the color alone. I would use background-color, no need to abbreviate.


Log in to reply