How to delete all rows from QTableWidget

前端 未结 10 1888
自闭症患者
自闭症患者 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:27

    The simple way to delete rows is to set the row count to zero. This uses removeRows() internally.

    table->setRowCount(0);
    

    You could also clear the content and then remove all rows.

    table->clearContents();
    table->model()->removeRows(0, table->rowCount());
    

    Both snippets leave the headers untouched!

    If you need to get rid of headers, too, you could switch from clearContents() to clear().

提交回复
热议问题