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. automatic tab indentation after new line (textEdit element)
Forum Updated to NodeBB v4.3 + New Features

automatic tab indentation after new line (textEdit element)

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 157 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.
  • V Offline
    V Offline
    veryQTguy
    wrote on last edited by veryQTguy
    #1

    We are working on an Code Editor in our Company, for that we are using an textEdit element in our qml program.
    What I am trying to achieve is that after a new Line an automatic Tab indentation is placed, like in popular IDEs like Visual Studio

    this is the code I already have for that in my textedit element:

    Keys.onPressed:
    {
    if(event.key === Qt.Key_Return || event.key === Qt.Key_Enter)
                    {
                        pos1 = edit.cursorPosition //helping variable to reset actual position in line
                        console.log("lastTab nach enter: " + posDifference)
    
                        let spaces = "";
                        for(let i = 0; i < posDifference; i++)
                        {
                            spaces += " "
                            console.log("Iterator:" + i)
                        }
                    }
    }
    
    onLineCountChanged: /
                {
                    update()
                    console.log("string to write:"+ spaces)
                    edit.cursorPosition = edit.length
                    edit.insert(edit.cursorPosition,spaces)
                }
    

    the problem is that the blank spaces are placed in the previous line not in the new Line. I have no idea how to fix.
    Note: posDifferent is the actual Position in the current line

    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