Reputation: 293
In a QTableView, I need to find the index of the field where it is clicked. I have the following method where i want to paste the value from the clipboard by pressing "ctrl+v" in the field of the table that is clicked:
QShortcut(QKeySequence('Ctrl+v'),self).activated.connect(self._handlePaste)
# paste the value
def _handlePaste(self):
clipboard_text = QApplication.instance().clipboard().text()
#item = QTableWidgetItem()
#item.setText(clipboard_text)
NvmQtModel.setData(self, index, clipboard_text, Qt.DisplayRole)
print clipboard_tex
Update:
# paste the value
def _handlePaste(self):
clipboard_text = QApplication.instance().clipboard().text()
index = QItemSelectionModel.selectedIndexes()
NvmQtModel.setData(self, index, clipboard_text, Qt.DisplayRole)
Exception:
index = QItemSelectionModel.selectedIndexes()
TypeError: QItemSelectionModel.selectedIndexes(): first argument of unbound method must have type 'QItemSelectionModel'
Upvotes: 0
Views: 573
Reputation: 8994
QAbstractItemView::indexAt method is for your question. But I propose you to work with selection model instead of detecting clicks.
Upvotes: 1