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
Get Man Pages for Driver Functions
Awk Command to Create Sha2 of Individual Column and Paste into New File
Shell Programming: Executing Two Applications at The Same Time
Dynamically Pick The User Gui and UId Who's Running Docker at The Host from Entrypoint
Is There Compatible Odbc Driver with Mariadb 10 on Linux
Is There Any Difference Between '=' and '==' Operators in Bash or Sh
Linux - Run Android Emulator on Nouveau Driver
How to Convert a Text/Plain to Text/X.Shellscript
How to Specify a Local Bond Interface to Multicast Socket in Haskell
Capturing User-Space Assembly with Ftrace and Kprobes (By Using Virtual Address Translation)
Sox Batch Process Under Debian
Producer Consumer Implementation in a Block Device Driver
Undocumented Switches for 'Date' Command
Home Directory Is Not Created with Adding User Resource with Chef
How to Write on Serial Port Using Qextserialport
Statically Linked Shared Object? or a Corrupt File