Guys,
I have a QTreeWidget holding a constantly updating view display. When the item list grows too big, I want to remove some of them. The example code is as following:
// remove the top 10 rows
for (int i = 0; i < 10; i++)
delete treeWidget->takeTopLevelItem(0);
// append a new row
treeWidget->addTopLevelItem(new someItem);
The intension of this code is to remove the top 10 items from the view, the add a new row. I figured that after remove the first row, the view re-arranges itself so that the second row becomes the first row, and so on. But, the reality is different: except the first row, other 9 removed rows were not from the top 10 rows, they are random! They could be from the rows I do not intend to remove! The worst is, the view is not consolidated after the deletion, and left the empty rows in it.
My question: how do I properly remove multiple rows from a QTreeWidget? I programed Windows MFC for more than 15 years, I probably have my logic following the MFC thinking all the way. QT might be different.
Thanks!
YR
Bookmarks