Display bulk data on QTableWidget
-
Hi,
I need to display bulk data on QTableWidget, for which I need to show all the data at one go. Currently, I am running the following script which populates the data on QTableWidget in an item by item manner. I am using dataframe (python) to store data and showing it pushing data item by item on QtableWidget. This is how I am doing it right now:
self.ui.out_table.setRowCount(df.shape[0]) for row in range (0, df.shape[0]): for col in range (0, len(df.columns) + 1): data = str(final_data.iloc[row, col] ) self.ui.out_table.setItem(row, col, QTableWidgetItem(str(data)))
Is there a way by which I can display the complete dataframe in one go?
-
Hi
QTableWidget is item based and you give it data by inserting items.
Im not sure what you mean "in one go"
There is no way around using items.You could use the View version and a custom model and store the data directly in model.
http://doc.qt.io/qt-5/qabstracttablemodel.htmlAlternatively, if its just so data is shown at same time, you can use
setUpdatesEnabled(bool)
so it first draws when finished adding. -
@Piyush
In addition to what @mrjj writes, note http://doc.qt.io/qt-5/qtablewidget.html#setItem:If you want to set several items of a particular row (say, by calling setItem() in a loop), you may want to turn off sorting before doing so, and turn it back on afterwards; this will allow you to use the same row argument for all items in the same row (i.e. setItem() will not move the row).