problem with tableview when view a large number of data
Solved
General and Desktop
-
I use a table view to view my item using QStandarditemModel and QStandareditem the I have 6230 row and 5 column I view it in the table it works fine but the problem start when I use this code to stretch the horizontal and fit to the content of vertical
void Quran::Extend() { int gg = ui->tableView->horizontalHeader()->count(); int ff = ui->tableView->verticalHeader()->count(); for (int c = 0; c < gg; ++c) { ui->tableView->horizontalHeader()->setSectionResizeMode(c, QHeaderView::Stretch); } for (int i = 0; i < ff; i++) { ui->tableView->verticalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents); } }
i try this too
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
but when i use this part of code it take about 15 second to view the model so i ask if theres a better (efficient) way to view this large number of data with this properties strecthed and resized to content of horizontal and vertical
thanks in advance -
Three ideas (all can be combined, even):
- while populating the view initially, store data on how wide and tall your cells should be (example:
int maxWidth = qMax(maxWidth, currentCellWidth);
), then use that number to manually set each column width and row height - only calculate row and column dimensions for visible items. It's unlikely your users will need to see all 6230 rows at once
- use lazy initialization to only load parts of the data (see canFetchMore() and fetchMore() methods in Qt's abstract model classes)
- while populating the view initially, store data on how wide and tall your cells should be (example: