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

How to change styleCheet on Event?



  • Hey everyone, I'm working with opencv object detection in pyqt5 and I want to change the color of an appended text of the textbrowser when event happended/ object detected.
    Anyone an idea what to do to change the style on event?
    Thx in advance.



  • @levoxtrip
    Just put a signal on whatever when it changes, and in your slot go textBrowser.setStyleSheet().

    Note this will affect the style sheet for the whole QTextBrowser. If you only want to do something about the style of the newly appended text you will have to do something rather different (e.g. insert in-line HTML/style).



  • ah nice thank you.
    Another question. Do you know how to reverse the textBrowser. So the newest append is on the top and the older are fading to the top?



  • @levoxtrip
    I don't know anything about your "fading", but QTextEdit::append() always appends the text at the end. To insert somewhere else it looks like you must use QTextEdit::insertHtml/insertPlainText(), and those insert at the current cursor position, so you may need to move it with QTextEdit::moveCursor/setPosition() or similar.


Log in to reply