Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect doubleClick in QTableView

Tags:

qt

qt4

pyqt

I'm using PyQt to create a GUI application. In a view inherited from QTableView, need to detect the row the user has selected when they double click a row. The table has sorting, but no editing.

How do I do it?

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

Ian

like image 419
Ian Avatar asked Dec 01 '10 11:12

Ian


3 Answers

I dont understand. The doubleClicked signal of the QTableView has the signature

void doubleClicked ( const QModelIndex & index )

If you connect that signal you should obtain the correct QModelIndex.

like image 199
Haplo Avatar answered Sep 18 '22 12:09

Haplo


No need to use SIGNALs anymore:

self.your_table.doubleClicked.connect(your_function)

"doubleClicked" being inherited from QAbstractItemView.

like image 24
regomodo Avatar answered Sep 19 '22 12:09

regomodo


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

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

You then can use these row and col values to access the table with table.setItem(row, column, newdata) or other table method

like image 33
Vicky T Avatar answered Sep 16 '22 12:09

Vicky T