<s> from PyQt4 . QtCore import Qt <EOL> from PyQt4 . QtGui import QTableView , QAbstractItemView <EOL> class EditableTableView ( QTableView ) : <EOL> def keyPressEvent ( self , event ) : <EOL> if event . key ( ) == Qt . Key_Return and self . state ( ) != QAbstractItemView . EditingState : <EOL> selected = self . selectionModel ( ) . selectedIndexes ( ) <EOL> if selected : <EOL> selected = selected [ <NUM_LIT:0> ] <EOL> self . setCurrentIndex ( selected ) <EOL> self . edit ( selected ) <EOL> else : <EOL> QTableView . keyPressEvent ( self , event ) </s>
