How to detect doubleClick in QTableView

I am using PyQt to create a GUI application. In a view inherited from QTableView, you must define the row selected by the user by double-clicking on the row. The table sorts, but does not edit.

How can I do it?

Note. I tried the doubleClicked (int) signal. It is emitted by mouse buttons, not data cells, so it never started. :(

Yang

+7
qt qt4 pyqt
source share
3 answers

I do not understand. The doubleClicked signal for QTableView has a signature

void doubleClicked ( const QModelIndex & index ) 

If you connect this signal, you should get the correct QModelIndex.

+14
source share

No longer need to use SIGNALS:

 self.your_table.doubleClicked.connect(your_function) 

"doubleClicked" is inherited from QAbstractItemView.

+3
source share

Once you have modelIndex (from Frank's comment above), you can use it to find which cell has been double clicked.

 def slotDoubleClicked(self, mi): row = mi.row() column = mi.column() 

You can then use these row and column values ​​to access the table using table.setItem (row, column, newdata) or another table method

+3
source share

All Articles