PDA

View Full Version : virtual keyboard and key press event



bibhukalyana
8th July 2014, 18:06
Hi everyone,
I have a virtual keyboard widget. I want to send key press event to the focused child widget of top widget from virtual keyboard.
What i know for qt embedded QWSServer will do this work.(Am I correct ?)

Can anybody suggest something ?

bibhukalyana
10th July 2014, 04:17
I am trying to send keypress event to the focus widget.



QKeyEvent keyEvent(QEvent::KeyRelease,keyId, Qt::NoModifier, text, false, 1);
QCoreApplication::sendEvent(m_focusedWd, &keyEvent);


But it is not working.

Same thing in a different way

keyboard class:


QKeyEvent keyEvent(QEvent::KeyRelease,keyId, Qt::NoModifier, text, false, 1);
QCoreApplication::sendEvent(m_activeWindow, &keyEvent);


Mainwindow:


QKeyEvent keyEvent(QEvent::KeyPress,event->key(),event->modifiers(),event->text(),false,1);
QApplication::sendEvent(this->focusWidget(),&keyEvent);


It is working. I am able to send text to line edit.
But problem is if I press enter then it will in infinite loop and after a while program will crash.

But i tried QInputMethodEvent in keyboard class.


QInputMethodEvent ev;
ev.setCommitString(text);
QCoreApplication::sendEvent(m_focusedWd,&ev);


I am able to set text only.
How i will send backspace kind of special key ?

Why keypress event is not able to send to focus widget ?

thanks.