How can I catch keystroke to Qt application?
-
wrote on 28 Jun 2011, 05:26 last edited by
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.. -
wrote on 28 Jun 2011, 05:32 last edited by
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 -
wrote on 28 Jun 2011, 05:52 last edited by
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
-
wrote on 28 Jun 2011, 06:06 last edited by
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).
-
wrote on 28 Jun 2011, 06:13 last edited by
@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
-
wrote on 28 Jun 2011, 06:19 last edited by
are you writing your own inputpanel ?? or you just want to do conversion logic inside this class???
-
wrote on 28 Jun 2011, 06:33 last edited by
Yes, I'm trying to make own input method.
But I don't know where can I catch those KeyPress EventI don't want to use platform dependent methods such as iBus, SCIM.
And this input method is use only for Qt application
Plz help me
Thanks -
wrote on 28 Jun 2011, 06:38 last edited by
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..
-
wrote on 28 Jun 2011, 06:43 last edited by
OK
Really thanks
what I means is virtual keyboard, that's it :)
But not on screen keyboard..
Thanks a lot -
wrote on 28 Mar 2012, 02:28 last edited by
Have any solutions on this issue?