c++qtqwidgetqtguiqevent

Qt tab order keys


A user can step through the widgets of QtGUI via key "Tab" or via arrow keys "<-" and "->".

Does anybody know how to disable the arrow keys for this purpose? I need the arrow keys for something else.


Solution

  • You would need to reimplement the corresponding event in your own QWidget subclass as follows:

    bool MyWidget::keyPressEvent(QKeyEvent *keyEvent)
    {
        if (keyEvent->key() == Qt::Key_Left || keyEvent->key() == Qt::Key_Right) {
            // Do nothing
        } else {
            QWidget::keyPressEvent(keyEvent);
        }
    }