How to delete all rows from QTableWidget

前端 未结 10 1887
自闭症患者
自闭症患者 2021-01-31 14:57

I am trying to delete all rows from a QTableWidget . Here is what I tried.

for ( int i = 0; i < mTestTable->rowCount(); ++i )
{
    mTestTable->removeRo         


        
10条回答
  •  醉酒成梦
    2021-01-31 15:35

    Look this post : http://forum.qt.io/topic/1715/qtablewidget-how-to-delete-a-row

    QList items = table.findItems(.....);
    QMap rowsMap;
    for(int i = 0; i < items.count(); i++{
      rowsMap[items.at(i).row()] = -1; //garbage value
    }
    QList rowsList = rowsMap.uniqueKeys();
    qSort(rowsList);
    
    //Now go through your table and delete rows in descending order as content would shift up and hence cannot do it in ascending order with ease.
    for(int i = rowList.count() - 1; i >= 0; i--){
      table.removeRow(rowList.at(i));
    }
    

提交回复
热议问题