在QTableView中,我需要找到单击它的字段的索引。我有以下方法,我想通过在单击的表的字段中按“ctrl + v”从剪贴板粘贴值:
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
更新
# paste the value
def _handlePaste(self):
clipboard_text = QApplication.instance().clipboard().text()
index = QItemSelectionModel.selectedIndexes()
NvmQtModel.setData(self, index, clipboard_text, Qt.DisplayRole)
例外:
index = QItemSelectionModel.selectedIndexes()
TypeError: QItemSelectionModel.selectedIndexes(): first argument of unbound method must have type 'QItemSelectionModel'