I use a QTableView and a model subclassed QAbstractTableModel to display the items which is increasing per second. And in order to display the items number which is selected by user, I use QItemSelectionModel.The attachment complete the task.But there is a strange bug.
The selction setting of tableview is
ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui.tableView->setSelectionMode(QAbstractItemView::MultiSelection);
To copy to clipboard, switch view to plain text mode
And the critical codes which bring bug are
QHeaderView* VerHeaderView
= ui.
tableView->horizontalHeader
();
VerHeaderView->swapSections(1,2); //this is critial for the behavior of m_selectionModel
QHeaderView* VerHeaderView = ui.tableView->horizontalHeader();
VerHeaderView->swapSections(1,2); //this is critial for the behavior of m_selectionModel
To copy to clipboard, switch view to plain text mode
If I selected items in the tableview by push down left button of mouse,draw diagonal line of a rectangel,the release the button. The displayed number of selected items is totally wrong.
If deleted the critical codes, repeat the selection in the same way. This time, the displayed number is right. I want to know, where is the mistake?
Bookmarks