Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QKeyEvent: check if the character is a letter or a digit



  • I have a custom keyPressEvent handler in a QWidget. I'd like to be able to decide if the key that has been pressed is a letter/number or if it is something else (e.g. alt, control, ...). Formerly, I've been simply comparing the keycode to the literal values of Qt::Key_A through Qt::Key_Z, and Qt::Key_0 through Qt::Key_9. However, that doesn't work for special Unicode characters (such as things like "ĉ"). Is there any way to simply figure out whether the value of the key is a letter/number or not?



  • Use QKeyEvent::text() to get a QString of the input.


Log in to reply