Home > Software engineering >  Track text insertion in QTextBrowser
Track text insertion in QTextBrowser

Time:12-19

I am making an application and using QTextBrowser to show messages. It should parse ascii colors, so my class (say MessageBoard) is inheriting from QTextBrowser. I can replace ascii color code and set MessageBoard's text color according to the ascii code before insertion.

But there are many ways of inserting text into the QTextBrowser, so MessageBoard should be able to detect exactly where text is inserted and what is its length.

The problem is, QTextBrowser (through QTextEdit) provides only textChanged signal but there is no way to get where changes happened.

So is there no way to get it or I missing something?

CodePudding user response:

If I understand your request well, I guess you may want to use this signal https://doc.qt.io/qt-5/qtextdocument.html#contentsChange

You will get access to QTextDocument with this https://doc.qt.io/qt-5/qtextedit.html#document-prop

CodePudding user response:

I hope "toplainText()" function can be used to get the text when we receive the signal "textChanged".

  • Related