[PyQt] Re: Tab key navigation in QtableView

Nicolas Girard nicolas.girard at nerim.net
Tue Sep 25 23:39:15 BST 2007

On Tue, 15 May 2007 11:55:35 +0100, joanne matthews (RRes-Roth) wrote:
> Can anyone explain why in the PyQt example queryModel.pyw, pressing tab
> after editing a cell in the qtableview displayed by EditableSqlModel,
> the current index is set to 0,0? I'd like to use the example for
> something similar but after editing a cell and pressing tab, I'd like
> the cursor to go to the next cell.

I could find a solution to this, after having a look into the Qt sources.

In editing mode, pressing tab makes QAbstractItemView.closeEditor() call
QAbstractItemView.moveCursor(MoveNext, Qt::NoModifier).

With this in mind, we can reimplement QAbstractItemView.moveCursor such as:

    def moveCursor (self, cursorAction, modifiers ):
        if cursorAction==QtGui.QAbstractItemView.MoveNext 
            and modifiers==QtCore.Qt.NoModifier:
            (col, row, parent)=(ix.column(), ix.row(), ix.parent())
            if col < self.model().columnCount(parent)-2:
                return self.model().index(row, col+1, parent)
        return QtGui.QTreeView.moveCursor(self, cursorAction,  modifiers)

Hope that helps,

More information about the PyQt mailing list