set Tab Order in a QTableWidget
Hello, I have the following problem:
I have a QTableWidget with 3 rows and 4 columns. The first 3 columns of each row are fixed with written data, but the last column is always editable.
It looks kind of like this, when f is a fixed cell and the _ is an editable cell:
f f f _
f f f _
f f f _
What I want to happen is that once the user is in the first editable cell and clicks tab, it should jump to the next editable cell and so on.
I am using only QTableWidgetItems in the QTableWidget. This is why the function QWidget::setTabOrder( QWidget*, QWidget*) does not work, because a QTableWidgetItem is not derived from QWidget
Any ideas how else I could do that?:confused:
I am using Qt 4.2.2 on Windows
Re: set Tab Order in a QTableWidget
The easiest way might be to reimplement QAbstractItemView::focusNextPrevChild():
Code:
bool MyTableWidget::focusNextPrevChild(bool next)
{
// check if current column is the editable column
int currentColumn = currentItem() ? currentItem->column() : -1;
if (tabKeyNavigation() && currentColumn == 3)
{
// Qt::Key_Down instead of Qt::Key_Tab and Qt::Key_Up instead of Qt::Key_Backtab
QKeyEvent event
(QEvent::KeyPress, next ? Qt
::Key_Down : Qt
::Key_Up, Qt
::NoModifier);
keyPressEvent(&event);
if (event.isAccepted())
return true;
}
}