Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Unable to get highlighting working on TextEdit
Forum Updated to NodeBB v4.3 + New Features

Unable to get highlighting working on TextEdit

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmltexteditqsyntaxhighligh
2 Posts 1 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ribtoks
    wrote on last edited by ribtoks
    #1

    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?

    R 1 Reply Last reply
    0
    • R ribtoks

      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?

      R Offline
      R Offline
      ribtoks
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved