Keyevent from qml
-
Hi all,
I know that it's not ready for a qml to emit keyevent according to "this":https://bugreports.qt.nokia.com//browse/QTBUG-15496
May I know what is the recommended way to create a virtual button that create a new character entry in a textedit qml?
Thanks!
/bryan -
I don't know what the "recommended" way is, but I got it working by doing something like this:
- Create a C++ class (say KeyEmitter) which has a slot called sendKeyEvent(key, text, modifiers, whatever) - the slot, er, sends a key event ("sendEvent":http://doc.qt.nokia.com/4.7/qcoreapplication.html#sendEvent)
- Make an instance of KeyEmitter available in QML ("setContextProperty":http://doc.qt.nokia.com/4.7/qdeclarativecontext.html#setContextProperty)
- When you want to emit a key (eg. in your virtualButton.onClicked)
** Make sure you've set the focus on the item you want to send the key events to
** Call the KeyEmitter object's sendKeyEvent from QML/js