PDA

View Full Version : Raise key pressed event when button is clicked?



newstead
4th June 2009, 09:07
Hi,
I'm developing an embedded Qt application where the only input method will be using the touchscreen and have made a virtual keyboard mapped with QSignalMapper. When a user presses (touches, clicks) a button on the virtual keyboard I would like the same behaviour as if a real keyboard was used. How do I do that? I figure it should be something like:


void Widget::keySelected (const QString& key) {
int i = key.at(0).toAscii();
QKeyEvent::QKeyEvent ( QEvent::KeyPress, i, Qt::NoModifier, key, false, 1);
}
But that doesn't work.

The following code:

void Widget::keySelected (const QString& key) {
qDebug() << key;
}
gives the output of the keyvalue, e.g. "A" if the A-button is pressed.

Would be greatful if someone has a hint here :)

wagmare
4th June 2009, 09:11
i think this thread will be useful to u .. but may solve your problem .. try this
http://www.qtcentre.org/forum/f-newbie-4/t-catch-a-key-like-designer-20799.html

newstead
4th June 2009, 09:34
I'm afraid that didn't help. The problem isn't catching the events, but to raise new ones.

Lykurg
4th June 2009, 13:03
You can use QCoreApplication::sendEvent()/QCoreApplication::notify()/QCoreApplication::postEvent() for that. Theoretical, because once I tried to send mous event in a graphics scene I failed, but the case was a bit of complexer.

newstead
4th June 2009, 13:19
You can use QCoreApplication::sendEvent()/QCoreApplication::notify()/QCoreApplication::postEvent() for that. Theoretical, because once I tried to send mous event in a graphics scene I failed, but the case was a bit of complexer.

Thanks! That works fine. Only problem is that it overwrites existing text and not adding the new letter. Why is that?

Just to clarify, do I really need to write a eventhandler for each widget that are going to use the virtual keyboard? Isn't there any way to just simulate a physical keyboard and use Qt:s generic inputeventhandlers?

newstead
5th June 2009, 07:36
Nobody with any ideas?

nish
5th June 2009, 07:44
download the QtExtended source code.

go to
src/plugins/inputmethods/keyboard

there they have implemented a virtual keyboard. this may help

newstead
5th June 2009, 13:12
download the QtExtended source code.

go to
src/plugins/inputmethods/keyboard

there they have implemented a virtual keyboard. this may help

They use the QWSServer to send keyevents which obviously doesn't work on the desktop. It would have been convienient to be able to use some sort of generic Qt-feature for future reuse but I'll guess I have to go with QWSServer for now... thanks.