how to make the tablewidget cost less time?
-
here's the issue that I used the qtablewidget to show the data from the database.but I found that the creating the qtablewidget and tablewidgetitem part would cost nearlly 2 seconds ,in fact it only created 100 rows.how to make the code to save the time?
-
Use a custom model with a QTableView instead the convenience QTableWidget.
-
is there any solutions that without using the tableview?cause that the project was highly related to the qtablewidget it is hard to replace by using the tableview object.
-
Then it's going to be complicated.
You should benchmark the code you use to create that table widget. There might be some stuff that could be optimized.
In any case, if your application is that much dependent on QTableWidget, there might be some architectural consideration that should be addressed. -
For a QTableWidget you have to create the widget for every cell in the table view. This can take quite some time (depending on the number of rows and columns). The QTableView manages the individual widgets for the cells differently. Simply speaking, it just shows the widgets that are visible and reuses them when scrolling. This is why QTableView is the better choice for a lot of data.
However, you are saying that you have only 100 rows. If it is only a hand full of columns 2 seconds might be a little long (though 100 rows by 10 columns would already be 1000 widgets). Do you have a single call to the database to fetch the data? Or are you querying one row at a time?