开发者

Setting Tab Order for QTableView in Qt 4.4

开发者 https://www.devze.com 2022-12-22 03:22 出处:网络
I am having a QTableView that has data loaded with a QStandardItemModel in the form ParameterValue X10.456

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.
开发者_Go百科

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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消