View Full Version : QtableWidget and numbers of row
VitaliBR
3rd February 2011, 15:15
I Have a qtableWidget and must delete all existing rows when click a button, I am trying as follows, but it only deletes one row at a time
for (int i = 0; i < ui.tableWidget->rowCount(); i++)
ui.tableWidget->removeRow(i);
high_flyer
3rd February 2011, 15:29
Is this the real and full code?
Post few lines before and after as well please.
jano_alex_es
3rd February 2011, 15:32
try "clear" (delete all the items) or "clearContents" (delete all the items but the headers)
VitaliBR
3rd February 2011, 15:41
try "clear" (delete all the items) or "clearContents" (delete all the items but the headers)
I had tried "clearContents" but it clears the contents, leaving lines in the table, I need to remove the lines also :(
thanks
jano_alex_es
3rd February 2011, 16:34
So try "clear"... as far as I remember, it deletes all, even the lines.
VitaliBR
3rd February 2011, 16:59
So try "clear"... as far as I remember, it deletes all, even the lines.
It erases all the same, including the column names
there is no other way?
Or how do I put the names in the columns again? (I named the columns using the QTDesigner)
lol
Thanks
I tried this, but the program simply fails (crash) if I try to rename the columns
ui.tableWidget->clear();
ui.tableWidget->horizontalHeaderItem(0)->setText("Name");
ui.tableWidget->horizontalHeaderItem(1)->setText("IP/DNS");
ui.tableWidget->horizontalHeaderItem(2)->setText("Phone");
ui.tableWidget->horizontalHeaderItem(3)->setText("Situation");
jano_alex_es
3rd February 2011, 18:10
I think you delete the headers when you use "clear", so you need to create them again.
Something like:
QTableWidgetItem* pHeader1 = new QTableWidgetItem("Name");
ui.tableWidget->setHorizontalHeaderItem(0, pHeader1);
QTableWidgetItem* pHeader2 = new QTableWidgetItem("IP/DNS");
ui.tableWidget->setHorizontalHeaderItem(1, pHeader2);
//etc
VitaliBR
3rd February 2011, 21:01
I solved my problem:
for(int i = ui.tableWidget->rowCount() - 1; i >= 0; i--){
ui.tableWidget->removeRow(i);
}
Thanks :D
ChrisW67
3rd February 2011, 23:32
QTableWidget::setRowCount() will remove rows to decrease the row count. Set it to zero...
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.