Stopping the VerticalHeader to update on QTableview

Viewed 32

I am implementing a QTableview to display a huge amount of data. Instead of showing all at once, I am showing 10000 rows and dynamically adding and subtracting the data from the table. I am facing a problem when deleting the upper rows; the vertical header gets updated, and row numbers get changed. Any way to stop the vertical header from updating.


bool flag = 0;
int last_row = 1000;
int top_row = 0;
int margin = 30;
void DataTable::verticalScrollbarAction(int action) {
    if(((this->rowAt(0)) - margin) < top_row && flag == 1)
    {
        this->getTableModel()->GetData(top_row-101, top_row-1, 0);
        this->getTableModel()->removeRows(last_row -101, last_row -1);
        last_row -= 100;
        top_row -= 100;
    }
    else if ((this->rowAt(this->height()) + margin) > last_row)
    {
        flag = 1;
        this->getTableModel()->GetData(last_row, last_row+100, 1);
        this->getTableModel()->removeRows(0, 100);
        last_row += 100;
        top_row += 100;
    }
}
1 Answers

The below answer is just my guess. May be you can try a bit on it.

Get the vertical header object

QHeaderView *pHeaderView = yourTableView->verticalHeader();

Now go through the below documentation defaultSectionSize of QHeaderView

https://doc.qt.io/qt-6/qheaderview.html#defaultSectionSize-prop

By default, the value of this property is style dependent. Thus, when the style changes, this property updates from it. Calling setDefaultSectionSize() stops the updates, calling resetDefaultSectionSize() will restore default behavior.

May be what you can do is first call

pHeaderView->setDefaultSectionSize(QHeaderView::Fixed);

After you are done with your business, you can call below to restore default behavior.

pHeaderView->resetDefaultSectionSize();
Related