tags:

views:

257

answers:

2

Hi, I am having a QTableView that has data loaded with a QStandardItemModel in the form

Parameter    Value

  X1         0.456
  X2         0.123
 .... and so on.

Now i have to set the Tab Order property in such a way that i can traverse only through the values and not the parameters. i.e when the control is on 0.456 and if i press 'Tab' key, it has to go to 0.123 and not to X2 (the default behavior). Also the column Parameter has Edt Triggers disabled and i can change the values only.

I know QWidget::setTabOrder(QWidget*,QWidget*) but since I am setting the data through QStandardItemModel how can i acheive the desired Tab order in QTableView? I am using Qt 4.4 and Windows XP. Also i didn't use Qt designer to design the UI elements. Everything is through code only.

A: 

Subclass QTableView and override keyPressEvent. Check for the tab key in the event, call the base implementation otherwise. Get the currently selected index from the view's selectionmodel. Set the view's edittrigger to CurrentChanged, or put on your own QItemDelegate for manual control.

Pieter
+1  A: 

Actually the keyPressEvent is not emitted when you are editing, instead you have to reimplement closeEditor and check for the hint. If the hint is QAbstractItemDelegate::EditNextItem then change the selectionModel::currentIndex and use use QTableView::edit.

The other solution only works when you're not editing, but anyway it gave me an starting point so I'm giving it the bounty

armonge