Get string value from modified key press
Hi,
I’m working on a key event related function. I use keyPressEvent to read in the keyboard inputs. The key() and string() values work fine on single press key events, but there is a problem.
When I press a key combination (control + c, for example), I receive two events. One has key = Qt::Key_Control, which is good. But the other has key = Qt::Key_C and string = QString(). Is there a way to convert the Qt::Key_* values to QString, QChar, or something similar?
A simple search in the docs yielded nothing, but I really wish I could find something here before diving into mapping all keys by myself (and there’s the shift key modifier to consider…Aaaarrrrhh).
Thanks in advance.
9 replies
But text() is not available when modifiers present. :-( Well, I guess I’ll just manually mapped all non-alphanumeric keys on my keyboard. But how about keyboard layouts? £ instead of $ above 4 on british keyboard, ¥ instead of \ on Japanese keyboards, etc. Is there a way for me to detect this on run-time?
For alphabets the cases don’t matter, so for ctrl + c both CTRL + ‘C’ and CTRL + ‘c’ are fine. I don’t participate in the server side programming, so I’m not sure what they intend to do with non-ASCII keys. (Most likely they don’t care — the system we are building is not for public use, and we use mostly US-layout keyboards. My plan now is to ignore the problem and leave it for the testing team to worry about. :-p)
You must log in to post a reply. Not a member yet? Register here!



