QTableWidget's rows deletion and again insertion
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
Re: QTableWidget's rows deletion and again insertion
Quote:
Originally Posted by
darpan
(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().
Code:
tableWidget->verticalHeader()->hide();
By the way,
Quote:
Originally Posted by
darpan
Code:
tableWidget->clear();
while(tableWidget->rowCount())
{
int row=tableWidget->rowCount();
tableWidget->setRowCount(row-1); // delete one row at a time
}
is equivalent of
Code:
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.