How can I copy and paste multiple items/values of a QTableView to a text/ excel file?
My Code:
tab_table_view = QtGui.QWidget()
self.Tab.insertTab(0, tab_table_view, self.File_Name)
self.tableView = QtGui.QTableView(tab_table_view)
self.tableView.setGeometry(QtCore.QRect(0, 0, 721, 571))
self.model = QtGui.QStandardItemModel(self)
self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection
This line self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection
helps with selecting multiple items in QTableView but when I do CTRL+C and paste it only pastes the last item or value of the selection?
I have seen the line self.tableView.setEditTriggers(QAbstractItemView.AllEditTriggers)
but this one only applies to a single item in the table and ignores the extended selection.
Please help me this is the second time I am posting this question. Now, I am wondering if it is even possible? Please let me know Anyone!
The difficulty here is that the selected cells in the table may be non-contiguous and not in any particular order. So the task is to calculate the smallest rectangle that will include all the selected cells, and then create a data structure from that which is suitable for passing to a csv writer.
Below is a demo script that does this (based on this previous answer - the additions have been commented):
PyQt4:
PyQt5: