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.

    Rectangle {
      id: descriptionRect
      height: 30
      border.width: descriptionTextInput.activeFocus ? 1 : 0
      clip: true
    
      Flickable {
          id: descriptionFlick
          contentWidth: descriptionTextInput.paintedWidth
          contentHeight: descriptionTextInput.paintedHeight
          anchors.fill: parent
          interactive: false
          flickableDirection: Flickable.HorizontalFlick
          height: 30
          clip: true
          focus: false
    
          function ensureVisible(r) {
              if (contentX >= r.x)
                  contentX = r.x;
              else if (contentX+width <= r.x+r.width)
                  contentX = r.x+r.width-width;
          }
    
          TextEdit {
              id: descriptionTextInput
              width: descriptionFlick.width
              height: descriptionFlick.height
              text: description
              onTextChanged: model.editdescription = text
    
              Component.onCompleted: {
                  globalModel.initDescriptionHighlighting(index, descriptionTextInput.textDocument)
              }
    
              onCursorRectangleChanged: descriptionFlick.ensureVisible(cursorRectangle)
             }
         }
     }
    

    Any ideas how I can solve this?



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.