PDA

View Full Version : QTextEdit's textChanged() signal



bangqianchen
11th January 2010, 07:39
I want to know whether the user had changed the content of QTextEdit. However, this signal is also emited when formatting is applied, while the content had nothing changed in fact. both of the fellowing ways are failed, I don't know how to solve this problem! Any help is appreciated!


m_pText = new QTextEdit(this);
connect(m_pText->document(),SIGNAL(contentsChanged()),this,SLOT(slo t_setModified()));
//or this way
connect(m_pText,SIGNAL(textChanged()),this,SLOT(sl ot_setModified()));

wysota
11th January 2010, 10:11
"Formatting" as you understand it changes the contents of the document as well. There is HTML (or Qt rich text, to be exact) under the hood so changing formatting changes the document. If you want content highlighting that doesn't cause document contents to change, use QPlainTextEdit and QSyntaxHighlighter (you can use QTextEdit too, the main idea is to force the content to be plain-text only and do highlighting using QSyntaxHighlighter).