MichaelXanadu
MichaelXanadu

Reputation: 505

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.

Upvotes: 3

Views: 332

Answers (3)

L&#225;szl&#243; Papp
L&#225;szl&#243; Papp

Reputation: 53215

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);
    }
}

Upvotes: 4

nedlab
nedlab

Reputation: 11

I may use QAction for this purpose. So you wont need subclassing.

QTabBar *tabBar;
........................
QAction* pLeftArrowAction = new QAction(this);
pLeftArrowAction->setShortcut(Qt::Key_Left);
QAction* pRightArrowAction = new QAction(this);
pRightArrowAction->setShortcut(Qt::Key_Right);
tabBar->addActions(QList<QAction*>() << pLeftArrowAction << pRightArrowAction);

Upvotes: 1

ychuris
ychuris

Reputation: 772

Just reimplement event() or keyPressEvent() / keyReleaseEvent() of main window. In reimplemented methods you can place your desired actions.

Upvotes: 1

Related Questions