Question

Simple question. I'd like to use F2 or Enter for rename, and double click to open a file.

Using self.treeView.doubleClicked.connect(self.doubleclick) I can do things in my self.doubleClick method, but the renaming is still triggered.

The model is not read-only (model.setReadOnly(False)).

Was it helpful?

Solution

By default, the doubleClicked signal is emitted just before the normal editing action, which is carried out by the QAbstractItemView.edit function.

Fortunately, this function is virtual, so it can be reimplemented in a subclass:

class TreeView(QtGui.QTreeView):    
    def edit(self, index, trigger, event):
        if trigger == QtGui.QAbstractItemView.DoubleClicked:
            print 'DoubleClick Killed!'
            return False
        return QtGui.QTreeView.edit(self, index, trigger, event)

OTHER TIPS

I don't know if you have this in python versions, but in C++ Qt you just set the edit triggers in the QAbstractItemView:

void setEditTriggers ( EditTriggers triggers )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top