Somebody knows how to disable the tab key. I need to disable the use of tab key to move between fileds.
Thanks for your help
Printable View
Somebody knows how to disable the tab key. I need to disable the use of tab key to move between fileds.
Thanks for your help
Code:
{ if(e->key()==Qt::Key_Tab) { e->accept(); //do somthing if you want } else e->reject(); }
I have this error with your code:
error: ‘class QKeyEvent’ has no member named ‘reject’
I am using QT 3.3.6
You can try turn of TabFocus for each fields.
For example:
If you have one QPushButton and one QLineEdit in your window. You can try
mMyBtn->setFocusPolicy(QWidget::NoFocus);
mMyEdit->setFocusPolicy(QWidget::NoFocus);
Sorry, it should be e->ingnore();Quote:
Originally Posted by otortos
This is my code:
void Form1::keyPressEvent(QKeyEvent *e)
{
if(e->key()==Qt::Key_Tab)
{
e->ignore();
}
else
{
e->ignore();
}
}
and, when i press "tab" still move to the next field.
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.
Code:
// install event filter for all widgets, e.g. in "MyWidget" constructor QList<QWidget*> widgets = findChildren<QWidget*>(); widget->installEventFilter(this);
Code:
{ { if (k->key() == Qt::Key_Tab) { // filter tab out return true; } } return false; }
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.
Code:
QList<QWidget*> widgets = findChildren<QWidget*>(); widget->setTabOrder(widget, widget);