Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTableView only displays all data when scrolling down



  • 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?


  • Lifetime Qt Champion

    See for instance here


  • Lifetime Qt Champion

    See for instance here



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


Log in to reply