PDA

View Full Version : QTableWidget's rows deletion and again insertion



darpan
17th October 2006, 15:34
Hi,
(1) When i am inserting items in QTableWidget then rowcount is also appearing with each row. I don't want to show rowcount with each row. How i can hide this rowcount.
(2) I am using following code to delete items from the QTableWidget and then i have to again insert items in QTableWidget but when after deleting items i am inserting items then the column header are also disappear and column count like 1,2,3 appears in place of header. I am using QT4.1 on mac.

How i can keep unchanged QTableWidget's header after deleting rows in it.

I am using the following code to delete and then again insert items in QTableWidget:-

if(EditHeaderDlgObj->exec()==QDialog::Accepted)
{
tableWidget->clear();
while(tableWidget->rowCount())
{
int row=tableWidget->rowCount();
tableWidget->setRowCount(row-1); // delete one row at a time

}

HEADER_FILE *tmp = SearchHeaderStart;
int RowCount = 0,
row = 0;

QTableWidgetItem *item=NULL;

QString FileSize;
while(tmp)
{
row = tableWidget->rowCount(); // current row count
tableWidget->setRowCount(row+1); // add one row

item=new QTableWidgetItem(tmp->bSoftwareName);

tableWidget->setItem( RowCount, 0, item );

item=new QTableWidgetItem(tmp->bFileExt);
tableWidget->setItem( RowCount, 1, item );


FileSize= FileSize.setNum(tmp->dwFileSize/1024);
item=new QTableWidgetItem(FileSize);
tableWidget->setItem( RowCount, 2, item );



RowCount++;

tmp = tmp->next;
}//end of while
RemoveButton->setEnabled(FALSE);
EditButton->setEnabled(FALSE);
qApp->processEvents();
}



Thanks and Regards

jpn
17th October 2006, 19:30
(1) When i am inserting items in QTableWidget then rowcount is also appearing with each row. I don't want to show rowcount with each row. How i can hide this rowcount.

Are you talking about the vertical header? If so, try QTableView::verticalHeader() and QWidget::hide().


tableWidget->verticalHeader()->hide();


By the way,




tableWidget->clear();
while(tableWidget->rowCount())
{
int row=tableWidget->rowCount();
tableWidget->setRowCount(row-1); // delete one row at a time
}


is equivalent of


tableWidget->clear();
tableWidget->setRowCount(0);

with much less hassle. Removing rows one by one causes several repaints (which Qt might actually merge for you, but still...)

I somehow have a feeling that a QTreeWidget with multiple columns and root decoration disabled would be more appropriate for you. But anyway, could you please use [ code ]-tags around your code postings to make them more readable.