Search code examples
c++qtqkeyevent

How to check if [Shift + Tab] is being pressed in QT


How would one check if the SHIFT key is held and the TAB key is pressed with a QKeyEvent?

I've tried using:

(event->key() == Qt::Key_Tab && event->modifiers() == Qt::ShiftModifier)

However, the event->key() is not equal to Qt::Key_Tab whenever the shift key is held down.


Solution

  • If event->key() is printed in hexadecimal format:

    qDebug()<<QString("key: 0x%1").arg(event->key(), 8, 16, QChar('0'));
    

    you get what: "key: 0x01000002" then checking in the docs and you see that the key is:

    Qt::Key_Backtab 0x01000002
    

    So you have to use that key:

    if(event->key() == Qt::Key_Backtab)