How to refresh data on horizontal header of QTableWidget?
-
@mrjj
Here is the system time in relevent function:onPosCmd - start "22:06:33:908" setHeaderData 0 "22:06:33:908" setHeaderData 1 "22:06:33:908" setHeaderData 2 "22:06:33:909" setHeaderData 3 "22:06:33:909" setHeaderData 4 "22:06:33:909" setHeaderData 5 "22:06:33:910" setHeaderData 6 "22:06:33:910" setHeaderData 7 "22:06:33:910" setHeaderData 8 "22:06:33:911" setHeaderData 9 "22:06:33:911" setHeaderData 10 "22:06:33:911" setHeaderData 11 "22:06:33:911" setHeaderData 12 "22:06:33:912" setHeaderData 13 "22:06:33:912" setHeaderData 14 "22:06:33:912" setHeaderData 15 "22:06:33:913" onPosCmd - end "22:06:33:913" headerData 0 "22:06:33:953" headerData 1 "22:06:33:954" headerData 8 "22:06:33:956" headerData 9 "22:06:33:957" headerData 10 "22:06:33:958" headerData 11 "22:06:33:959" headerData 12 "22:06:33:960" headerData 13 "22:06:33:961" headerData 14 "22:06:33:962" headerData 15 "22:06:33:963" headerData 0 "22:06:33:976" headerData 1 "22:06:33:978" headerData 8 "22:06:33:980" headerData 9 "22:06:33:982" headerData 10 "22:06:33:984" headerData 11 "22:06:33:985" headerData 12 "22:06:33:987" headerData 13 "22:06:33:989" headerData 14 "22:06:33:990" headerData 15 "22:06:33:992"
It doesn't seem to waste much time on signaling.
-
What resize mode do you use? And can you provide a small test example so we can run it e.g. with callgrind to see where the time is spend.
-
@Christian-Ehrlicher
Hi,
The resize mode is QHeaderView::Stretch, this is the config of tableView:tableView = new QTableView(this); tableView->setModel(tableModel); tableView->setFrameShape(QFrame::NoFrame); tableView->horizontalHeader()->setVisible(true); tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); tableView->verticalHeader()->setVisible(true); tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); tableView->setSelectionBehavior(QAbstractItemView::SelectItems); tableView->setSelectionMode(QAbstractItemView::ExtendedSelection); tableView->setAlternatingRowColors(true);
-
@tovax said in How to refresh data on horizontal header of QTableWidget?:
The resize mode is QHeaderView::Stretch
Ok, this is at least not a problem for the update. So please provide a small testcase.
-
This post is deleted!
-
@Christian-Ehrlicher
Here is the github link:
TableView
Best Regards! -
@tovax: I'll give it a try today, thx
-
Looks like the culprit is that a header data change triggers a complete repaint through QAbstractItemView::updateGeometries() which is very expensive. It doesn't matter if you call headerDataChanged() once per section or completely - it's a delayed trigger.
-
@Christian-Ehrlicher
Hi,
In other words, can't I update the data on the horizontal header, please?
Best Regards! -
@tovax
Hi
Nope, not as fast as you wish.
On my (albeit old) gamer pc, it uses 28% CPU to refresh it.
So for less powerful system, you will have to find another way to do the same
than using the headers. Its too expensive to be used in this way.
( even 'just' 10 times pr second )So basically its not a supported use case with Qt to have high-speed header refresh. That said you might be able to fix it with a custom HeaderView
but if there is enough virtual function to override this behavior, i cannot say currently. -
Or, as we said already more times - don't try to update at 100Hz - noone can ever read this...
-
Solved:
- Derived from QAbstractTableModel + QTableView
- Create two QTableView, one for cell's data, another for header data.
- Frozen the first row of the QTableView used for header data, and refresh data in it (100Hz).
- (Refer to official demo: Frozen Column Example)