Important: Please read the Qt Code of Conduct -

Read keyboard input that can differ between LEFT Shift and RIGHT shift key

  • Hi, I am writing an application to test keyboards. I have to read input from both the shift buttons, the one on the right and the one on the left, and also for the right and left windows buttons.

    I haven't written any Qt before, but if anyone could write up some example code on how I can capture these inputs from e.g. a QLineEdit (I want to show what character is being typed, irregardless of which shift-button the user press) I would really appreciate it!

    As a bonus, how can I read e.g. ctrl+shift, win+tab etc?

  • Qt Champions 2017

    There is no direct Qt::Key_* like that. You need to look at the native scan code and work on this.

    i.e check for QKeyEvent::nativeScanCode(). This is platform dependent scan code.

    For other question you can use Qt::ControlModifier.

  • Thank you. What I struggled with first and foremost was to actually override the QKeyEvent in my widget.
    Thanks for your reply.

  • Qt Champions 2017

    oh. If you had asked that earlier, I would have provided you the sample source code. Any not too late.

    Are you able override the QKeyEvent ? You can following snippet of code for the same.

    @void Widget::keyPressEvent(QKeyEvent *event){
    if (event->modifiers() & Qt::ShiftModifier & Qt::ControlModifier) {
    qDebug() << "Key board modifier is pressed " << endl;

  • Yes, I got it to work. Figured out the protected keyword in the header file also :) how can I now "un-override" it? Not that I need it, but just out of curiousity

Log in to reply