Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Tab Order for QTableView in Qt 4.4

Tags:

c++

qt4

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.

like image 856
liaK Avatar asked Mar 09 '10 06:03

liaK


2 Answers

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.

like image 93
Pieter Avatar answered Nov 06 '22 09:11

Pieter


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

like image 38
armonge Avatar answered Nov 06 '22 11:11

armonge