Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. problem with tableview when view a large number of data

problem with tableview when view a large number of data

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 505 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AmrCoder
    wrote on 30 Dec 2016, 21:27 last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 31 Dec 2016, 09:34 last edited by sierdzio
      #2

      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)

      (Z(:^

      1 Reply Last reply
      3
      • A Offline
        A Offline
        AmrCoder
        wrote on 31 Dec 2016, 13:46 last edited by
        #3

        Thank you @sierdzio I solve this with the first one I calculate the maximum column length and width and set all a fixed width and column it loads the table view with 6230 row in 1 second

        1 Reply Last reply
        0

        1/3

        30 Dec 2016, 21:27

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved