Important: Please read the Qt Code of Conduct -

How can I send keyevent into a qml textedit?

  • Hi,

    For qtextedit, i can use coreapplication.sendevent(qtextedit, keyevent) to send in the specific keyevent.

    However for qml textedit, how can i do the same thing?


  • sendEvent function requires reciever to be a QObject and textEdit item inherits QObject so you can still send event to textEdit. only thing you need to do is get access to textEdit from a c++ code and send events from there to textedit. For getting access to qml items in C++ please check

  • Am I able to pass the keyevent to a QDeclarativeView? I read it in Keyboard Focus in QML. But i'm not sure how to do so.

    Please advise. Thanks!!!

  • well if your textEdit is in focus and only then you want to send the events then you can send event directly to the QDeclarativeView itself, QDeclarativeView should take care of forwarding keyevent to textEdit.

    QCoreApplication::sendEvent(declarative_view, keyEvent);

  • I tried to send key event to TextInput with coreapplication.sendevent but it does not work.
    Anyone has a code sample ?

Log in to reply