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. Qml TextEdit Custom key event not processed properly
Forum Update on Monday, May 27th 2025

Qml TextEdit Custom key event not processed properly

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 204 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.
  • C Offline
    C Offline
    chilarai
    wrote on 26 Apr 2021, 17:18 last edited by
    #1

    I wanted to add custom key events to a TextEdit. But, it seems key events are not properly processed inside TextEdit.

    For example, in the code below, I am trying to handle Space key events. Although the Space keypress is recognized by the signal handler function, the output text does not contain a space. It is the same for all other key events. How do I overcome this?

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    
    Item{
    
        function processSpace(event){
            event.accepted = true
            console.log(xTextEdit.text)
        }
    
        TextEdit{
            id: xTextEdit
            height: parent.height
            width: parent.width
            Keys.onSpacePressed: processSpace(event)
        }
    }
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      chilarai
      wrote on 27 Apr 2021, 10:05 last edited by
      #2

      Seems like I have to write event.accepted = false and then it works

      1 Reply Last reply
      0

      1/2

      26 Apr 2021, 17:18

      • Login

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