Is it possible to deselect in a QTreeView by clicking off an item?

后端 未结 8 1217
盖世英雄少女心
盖世英雄少女心 2020-12-30 05:35

I\'d like to be able to deselect items in my QTreeView by clicking in a part of the QTreeView with no items in, but I can\'t seem to find anyway of doing this. I\'d intercep

8条回答
  •  天命终不由人
    2020-12-30 06:12

    To add to @Skilldrick's answer, if you need to apply this to a view that has already been instantiated because you're using Qt Designer, you can do something like this:

    import new
    def mousePressEvent(self, event):
        self.clearSelection()
        QtGui.QTableView.mousePressEvent(self, event)
    self.ui.tableView.mousePressEvent = new.instancemethod(mousePressEvent, self.ui.tableView, None)
    

    This assumes that your view is self.ui.tableView.

    Thanks to this answer: https://stackoverflow.com/a/1647616/1300519

提交回复
热议问题