PDA

View Full Version : how to emit double click on cell Signal in QTableView from right click menu



krystosan
6th January 2014, 17:28
In my QTableView I have a model MyDataModel that inherits from QAbstractTableModel to which I have added the below method to be able to rename the item by double clicking it!!






def flags(self, index):
""" This method sets the text in the cell editor selected
and editable and enabled.
"""
return QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable


But now I have also added a right click contextual menu on which i have added the rename option, so I want to trigger the double click behavior to rename the selected item the same way I did by double clicking it.

How can I achieve that?

anda_skoa
7th January 2014, 00:32
Call the edit() slot of the view with the respective model index.

Cheers,
_

krystosan
7th January 2014, 17:42
Call the edit() slot of the view with the respective model index.

Cheers,
_

I don't know how to do that, can you give an example...

Added after 8 minutes:

Do you mean like this

self.connect(self, SIGNAL("edit()"), SLOT("renAction"))

anda_skoa
7th January 2014, 23:15
Obviously the mention of "slot" got you confused, let me rephrase:
call the view's edit() method, i.e. this one: http://qt-project.org/doc/qt-4.8/qabstractitemview.html#edit

Cheers,
_

krystosan
11th January 2014, 04:06
thanks
elf.edit(self.selectionModel().currentIndex())