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. QTableView only displays all data when scrolling down
Forum Update on Monday, May 27th 2025

QTableView only displays all data when scrolling down

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 769 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.
  • C Offline
    C Offline
    christian20052
    wrote on last edited by
    #1

    Hi,
    I am building a custom database/tableviewer-program. I use QTableView to display the data and I am facing the following issue: When I initially load the table, only 256 rows are depicted although the table has more than 12000 rows. As I scroll down however, these rows get "dynamically added" as you can see in this sequence of pictures (note the row number and scroll bar height):

    t1.png
    t2.png
    t3.png
    t4.png
    Scrolling back up:
    t5.png

    I already figured out that it is the underlying model which is missing the rows, however, I don't know how to properly update it.
    My code for the constructor:

    TableTab::TableTab(QString tablename_sql, QString time_lower_bound, QString time_upper_bound, QString filepath_prefix) : QWidget(){
    
        model = new QSqlTableModel(this);
    
        createTable(tablename_sql, time_lower_bound, filepath_prefix);
        addDataToTableByTime(tablename_sql, time_lower_bound, time_upper_bound, filepath_prefix);
    
        index_current_x_axis = -1;
        index_current_y_axis = -1;
    
        model->setTable(tablename_sql);
        model->select();
    
        QAction *action_ctrlc = new QAction(this);
        this->addAction(action_ctrlc);
        action_ctrlc->setShortcut(QKeySequence("Ctrl+C"));
    
        connect(action_ctrlc, &QAction::triggered, this, &TableTab::copy_button_clicked);
    
        mytableview = new QTableView;
        mytableview->setModel(model);
        mytableview->show();
        mytableview->setEditTriggers(QAbstractItemView::NoEditTriggers);
    
        this->setContextMenuPolicy(Qt::CustomContextMenu);
        mytableview->setContextMenuPolicy(Qt::CustomContextMenu);
        mytableview->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
    
        connect(mytableview, &QTableView::customContextMenuRequested, this, &TableTab::ShowContextMenuCopy);
        connect(mytableview->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, &TableTab::ShowContextMenuCopy);
    
    
    
        QPushButton *plot_button = new QPushButton("Plot x-y data");
        connect(plot_button, &QPushButton::clicked, this, &TableTab::plotSelectedData);
    
        QLabel *label_export = new QLabel("Filepath including file extension:");
        checkbox_header = new QCheckBox();
        checkbox_header->setText("Include column names as header when exporting or pressing Ctrl+C");
        lineedit_export = new QLineEdit("");
    
        QPushButton *export_button = new QPushButton("Export selection");
        connect(export_button, &QPushButton::clicked, this, &TableTab::exportSelection);
    
        QGridLayout *mainLayout = new QGridLayout;
        mainLayout->addWidget(mytableview,0,0,1,2);
        mainLayout->addWidget(plot_button,1,0);
        mainLayout->addWidget(label_export,2,0);
        mainLayout->addWidget(checkbox_header,2,1);
        mainLayout->addWidget(lineedit_export,3,0);
        mainLayout->addWidget(export_button,3,1);
    
        mainLayout->setVerticalSpacing(20);
        setLayout(mainLayout);
    
    }
    
    

    What might be wrong?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      See for instance here

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • C Offline
        C Offline
        christian20052
        wrote on last edited by
        #3

        Thanks, that solved it. I just didn't know what to search for.

        1 Reply Last reply
        0

        • Login

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