Results 1 to 2 of 2

Thread: Unable to get highlighting working on TextEdit

  1. #1
    Join Date
    Nov 2014
    Posts
    20
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11

    Default Unable to get highlighting working on TextEdit

    TL;DR: TextEdit paints highlighted text only when I click on it. Nothing helps

    I have a ListView with a QAbstractListModel model with string properties. Those string properties are being spellchecked and QSyntaxHighlighter is used to show spell errors. I create QSyntaxHighlighter descendant in Component.onCompleted of TextEdit. I double-checked highlighting get's executed with correct spell errors and setFormat() of Highlighter is executed with correct positions. The problem is that it draws text in red (invalidates) only when I click on the TextEdit itself.

    TextEdit lives in a Flickable (to track cursor) and Flickable lives in a Rectangle (to have nice background and border). Binding to some signals and calling update() of TextEdit does not help.

    After spellcheck finishes, I emit rehighlight() signal of created SyntaxHighlighter.

    Qt Code:
    1. Rectangle {
    2. id: descriptionRect
    3. height: 30
    4. border.width: descriptionTextInput.activeFocus ? 1 : 0
    5. clip: true
    6.  
    7. Flickable {
    8. id: descriptionFlick
    9. contentWidth: descriptionTextInput.paintedWidth
    10. contentHeight: descriptionTextInput.paintedHeight
    11. anchors.fill: parent
    12. interactive: false
    13. flickableDirection: Flickable.HorizontalFlick
    14. height: 30
    15. clip: true
    16. focus: false
    17.  
    18. function ensureVisible(r) {
    19. if (contentX >= r.x)
    20. contentX = r.x;
    21. else if (contentX+width <= r.x+r.width)
    22. contentX = r.x+r.width-width;
    23. }
    24.  
    25. TextEdit {
    26. id: descriptionTextInput
    27. width: descriptionFlick.width
    28. height: descriptionFlick.height
    29. text: description
    30. onTextChanged: model.editdescription = text
    31.  
    32. Component.onCompleted: {
    33. globalModel.initDescriptionHighlighting(index, descriptionTextInput.textDocument)
    34. }
    35.  
    36. onCursorRectangleChanged: descriptionFlick.ensureVisible(cursorRectangle)
    37. }
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 

    Any ideas how I can solve this?
    Last edited by ribtoks; 29th November 2015 at 13:09.

  2. #2
    Join Date
    Nov 2014
    Posts
    20
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11

    Default Re: Unable to get highlighting working on TextEdit

    Here is small sample project with demo of how it's not working until you click on a text https://bitbucket.org/ribtoks/rehighlighdemo/src

Similar Threads

  1. Replies: 2
    Last Post: 27th March 2014, 18:09
  2. QLabel highlighting
    By chandan in forum Newbie
    Replies: 1
    Last Post: 24th February 2011, 13:42
  3. unable to click the hyperlink in textedit
    By rleojoseph in forum Qt Programming
    Replies: 14
    Last Post: 17th January 2011, 07:26
  4. QwtSymbol highlighting?
    By shud in forum Qwt
    Replies: 1
    Last Post: 2nd October 2009, 22:42
  5. highlighting a QPushButton
    By qtUser500 in forum Qt Programming
    Replies: 6
    Last Post: 14th July 2009, 21:21

Tags for this Thread

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.