Qt5: tell QPlainTextEdit to ignore syntax highlighting changes

I have a widget QPlainTextEditin my application that is assigned QSyntaxHighlighter. Every time I change the content inside this text editing area, I need to receive a notification (to update the save / change state of the global application). However, the signal is textChanged()also emitted every time the marker works, and I need to filter it somehow.

I already watched modificationChanged(), but this also does not work. It ignores the highlight changes and successfully notifies me of the first change in content, but not of any subsequent changes. The documentation states that I should have reset the internal state with setModified(false), but this method does not seem to exist.

Any ideas on how to filter the changes?

I need to switch to QTextDocumentwhich one seems to have one contentsChanged()that said to ignore syntax highlighting changes?

+4
source share
3 answers

It turns out that I was already on the right track ... just not completely:

I really need to listen to signals modificationChanged, as they are emitted when content changes (which are important events for my processing of maintaining the state of the application).

, , reset (, ). , setModified(bool) QPlainTextEdit, , QTextDocument, . , , reset :

m_pPlainTextEdit->document()->setModified(false);

, , modificationChanged , , , "".

BTW: contentsChanged QTextDocument , .

+2

, .

, QKeyEvent.
, QInputMethodEvent (?)

, , QKeyEvent, , .

filterobject , QTextEdit.

bool MyClass::eventFilter(QObject *o, QEvent *e)
{
    if (e->type() == QKeyEvent) //The user modified the text edit
        return false;
    else
        return true;
}

(, ), , QTextEdit:

myTextEdit->installEventFilter(this);
+1

, modifyChanged() , textChanged(). , , , ...

-1

Source: https://habr.com/ru/post/1533709/


All Articles