This approach is wrong. The key press event goes directly to a focused child.
You could prevent the child from getting tab key press events by an event filter, but in my opinion that wouldn't be very good idea. I don't know what kind of widgets do you have, but some widgets have an "internal navigation" etc. with tab key. E.g. a date and time edit, which first changes the current field, and then after the last field changes the focus.
// install event filter for all widgets, e.g. in "MyWidget" constructor
QList<QWidget*> widgets = findChildren<QWidget*>();
widget->installEventFilter(this);
// install event filter for all widgets, e.g. in "MyWidget" constructor
QList<QWidget*> widgets = findChildren<QWidget*>();
foreach (QWidget* widget, widgets)
widget->installEventFilter(this);
To copy to clipboard, switch view to plain text mode
{
if (e
->type
() == QEvent::KeyPress) {
if (k->key() == Qt::Key_Tab)
{
// filter tab out
return true;
}
}
return false;
}
bool MyWidget::eventFilter(QObject* o, QEvent* e)
{
if (e->type() == QEvent::KeyPress)
{
QKeyEvent* k = static_cast<QKeyEvent*>(e);
if (k->key() == Qt::Key_Tab)
{
// filter tab out
return true;
}
}
return false;
}
To copy to clipboard, switch view to plain text mode
A better solution could be to trick the tab order. By this way you wouldn't prevent widgets from receiving and acting due to tab key press events.
QList<QWidget*> widgets = findChildren<QWidget*>();
widget->setTabOrder(widget, widget);
QList<QWidget*> widgets = findChildren<QWidget*>();
foreach (QWidget* widget, widgets)
widget->setTabOrder(widget, widget);
To copy to clipboard, switch view to plain text mode
Bookmarks