How can I catch keystroke to Qt application?
-
Dear all,
I want to make class to implement with all input widgets such as QLineEdit, QTextEdit & etc...
During when I focus on that input widgets, if I type "A" on keyboard, that class send respective asian character to focused input widget.How can I do that?
Plz help me...
Thanks in advance.. -
your question is not clear, can you add some more information.. If you are using QLineEdit or QTextEdit in your application, they automatically handle key events. Do you want to implement a class similiar to QLineEdit ??
To Catch key events, implement KeyPressEvent, KeyReleaseEvent inside your QWidget class.
http://doc.qt.nokia.com/latest/qwidget.html#keyPressEvent
http://doc.qt.nokia.com/latest/qwidget.html#keyReleaseEvent -
I would like to make a keyboard layout.
If I press keyPress on one character, class will send to focused input widget a respective character.
It like Microsoft keyboard layout for non-English language."QInputContext":http://doc.qt.nokia.com/latest/qinputcontext.html can send like that but its example is with "InputPanel.":http://doc.qt.nokia.com/latest/tools-inputpanel.html
I don't need to click these buttons just to convert keyPressEvent.Thanks
-
Ok got you... you need to do couple of things
- Write your own class class that derives from QInputContext
- Implement filterEvent of QInputContext and do your conversion logic
- Call sendEvent () to send your converted character to the focused widget.
- Install your QInputContext class on QApplication with setInputContext() method.
This is what happens, as soon as you press any key event, that event comes to your QInputContext class, you perform the conversion logic, and then send it to focused widget (check if this focused widget is a editor before doing your conversion logic).
-
@bool MyInputMethod::filterEvent(const QEvent *event)
{
if (event->type() == QEvent::RequestSoftwareInputPanel){
updatePosition();
//inputPanel->show();
return true;
} else if (event->type() == QEvent::CloseSoftwareInputPanel){
//inputPanel->hide();
return true;
} else if (event->type() == QEvent::KeyPress){
QMessageBox::about(0,"TEST","Key is Pressed");
return true;
}return false;
}@
I try to catch there but no catch to KeyPress
What's wrong with my method, plz guide me..Thanks
-
are you writing your own inputpanel ?? or you just want to do conversion logic inside this class???
-
Ok.. we did some work on virtual keypads long time back.. There are some tweaks that we need to do to catch events....
Let me refer back to the work we have done and get back to you..