Keyboard Input in Qt

Qt Widget - how to capture just a few keyboard keys

Your own comment says it all:

return TRUE; // eat event

As you return true for all keys, the event won't be further processed. You must return false for all keys you don't want to handle.

Another way without event filter but reimplementing keyPressEvent:

void MyWidget::keyPressEvent( QKeyEvent* event ) {
switch ( event->key() ) {
case Qt::Key_X:
//act on 'X'
break;
case Qt::Key_Y:
//act on 'Y'
break;
default:
event->ignore();
break;
}
}

QKeyPress - Simulating key press in Qt

In the link you indicate an enter is given so the text is not necessary, but in the case you want to send a letter you must pass that parameter:

ui->lineEdit->setFocus();
QKeyEvent *key_press = new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_X, Qt::NoModifier, "X");
// text ─────┘
QApplication::sendEvent(ui->lineEdit, key_press);

How to modify the keyboard input in QT?

Could this example be useful to you ?

They use a mecanism called completer, that provides different words for a given entry... It's quite like a dictionnary on a cell phone...

Custom Completer Example :

http://qt.nokia.com/doc/4.6/tools-customcompleter.html

Hope it helps a bit !

How can I intercept the pressing of multiply (*) key in my C++ Qt calculator app?

try using this case (Qt::Key_Asterisk):

Keyboard input in Qt

Can not believe this but setting the QWS_KEYBOARD variable as null solved the problem.
Found it in the Qt developer FAQ http://developer.qt.nokia.com/faq/answer/why_doesnt_my_keyboard_work_after_i_have_done_an_export_qws_keyboard_dev_tt

export QWS_KEYBOARD=""

Well, it did not completely solve the problem since I still have to include the native keypad along with the USB keyboard.

Anyway, I am able to move to fields using the arrow/TAB keys. Text input works well. Although CAPS-LOCK and NUM-LOCK do not seem to work. SHIFT works. I am able to terminate the application by Ctrl+Alt+Bkspce. So, for the time being, I am able to input text at least.

Will post if any improvements.



Related Topics



Leave a reply



Submit