how to save specific columns from tablewidget?
Unsolved
Qt for Python
-
Okay using the snippet you have given I believe this might help you with what you are trying to do. The part that comes before the saveData function is assumed to have been done somewhere else within your program but is essential for having the saveData function work properly. Now I used a QTreeView as opposed to a QTreeWidget but they are similar, however, you might have to tweak things a little if you need to use that QTreeWidget
tableWdgt = QTreeView() model = QStandardItemModel(0, cols) tableWdgt.setModel(self.model) def saveData(self): filename = QFileDialog.getSaveFilename(self,'Save File',os.getenv('Home')) rows = self.tableWdgt.model.rowCount() cols = self.tableWdgt.model.columnCount() with open(filename[0],'w') as filOut: for row in range(rows): for col in range(cols): if col in (0, 3): #grabs 1st and 4th columns cellValue = self.tableWdgt.model.item(row, col).text() filOut.write(cellValue)