0
votes

I have a dialog and a tab QTabWidget inside it, and inside that tab there is a table view. Please see the screen shot below enter image description here

the problem is when I press tab key from the text box in dialog (text box Telp) it goes to the tab Items and then when I click again it goes to the Table View but I never can get out of this Tab Items. Right now I'm using a QShortcut to escape from this Tab Items and go to the text area on the dialog. I want to use a Tab key to escape from this Tab Items. Is it possible?

2

2 Answers

0
votes

from doc:

void QWidget::setTabOrder ( QWidget * first, QWidget * second ) [static]

Puts the second widget after the first widget in the focus order.

Note that since the tab order of the second widget is changed, you should order a chain like this:

 setTabOrder(a, b); // a to b
 setTabOrder(b, c); // a to b to c
 setTabOrder(c, d); // a to b to c to d

not like this:

// WRONG

 setTabOrder(c, d); // c to d
 setTabOrder(a, b); // a to b AND c to d
 setTabOrder(b, c); // a to b to c, but not c to d

If first or second has a focus proxy, setTabOrder() correctly substitutes the proxy.

0
votes

OK I can solve this problem by subsclassing QTableView and override keyPressEvent event

void LMJTableView::keyPressEvent(QKeyEvent *event)
{
  if(event->key() == Qt::Key_Tab){
    //event->ignore();
    if (nextWidget!=NULL) {
      nextWidget->setFocus();
    }
  }
  else
    QTableView::keyPressEvent(event);
}