开发者

Modify Key press action in QTableView (PyQt4)

开发者 https://www.devze.com 2023-03-18 09:04 出处:网络
I\'m using the QTableView class to display a table from a database. I want to allow the user to edit the table using the keyboard only.

I'm using the QTableView class to display a table from a database. I want to allow the user to edit the table using the keyboard only.

However, the default behavior of the class is to reset the focus to the starting index of the table after 2 edits, ie. I edit a cell, press the "Down" key, edit the cell, again press the "Down" key, at which point the table loses focus; next time I press the down key, the first cell of the table gains focus.

What methods of the class should I look at to modify this behavior?

I'm using the single item selection mode:

开发者_运维问答    self.entryView = QTableView()
    self.entryView.setModel(self.logModel)
    self.entryView.setItemDelegate(LogDelegate(self))
    self.entryView.setSelectionMode(QTableView.SingleSelection)
    self.entryView.setSelectionBehavior(QTableView.SelectItems)


I used TreeWidget before so they should be similar. How about explicitly specifying the "active item" by calling setCurrentItem() method after modification? in this way you can always have the correct focus

0

精彩评论

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