how to save specific columns from tablewidget?
Unsolved
Qt for Python
-
wrote on 3 Jun 2019, 07:43 last edited by
I am using pyqt5...I have 5 columns in tablewidget with data . I want to save specific two column from tablewidget . how can do that?
-
I am using pyqt5...I have 5 columns in tablewidget with data . I want to save specific two column from tablewidget . how can do that?
-
wrote on 4 Jun 2019, 19:49 last edited by
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)
1/3