Results 1 to 3 of 3

Thread: QTextEdit, Highlighting and textChanged()

  1. #1
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTextEdit, Highlighting and textChanged()

    I have a QSyntaxHighlighter "installed" on a QTextEdit ( called textEdit).

    on_textEdit_textChange() sets a "document dirty" flag whenever the user changes the contents of textEdit.

    Works fine, BUT if I set the highlighter to highlight some text (in repsonse to user entered text in a lineEdit), it causes on_textEdit_textChange() to fire again thus setting my dirty flag although the text hasn't "really" changed.

    I tried putting a flag up saying "don't set document dirty" before firing up the highlighter and resetting it afterwards. Unfortunately, I think the highlighting process runs asynchronously (QSyntaxHighlighter::rehighlight is a slot) so my "don't set document dirty" flag has come and gone well before the highlighting is actually done.

    Any thoughts gratefully received!

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit, Highlighting and textChanged()

    maybe you have more luck with QTextDocument::contentsChanged()? (I fear you will not have that luck, but it is worth a try.)

  3. The following user says thank you to caduel for this useful post:

    onamatic (12th November 2008)

  4. #3
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit, Highlighting and textChanged()

    Thank you for that Caduel.

    Using the document's isModified() function genuinely reflects the correct state and ignores any highlighting in the QTextEdit. For the moment, I just test that function in on_textEdit_textChanged and all is well.

    I will rewrite it to use QTextDocument::contentsChanged() eventually; it's clearly the correct thing to do.

    Thank you for an excellent solution.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.