Question

I have a table. And an item.

How can I use only one Item to fill part of the table?

If I set item to one position and then take item, I lose text at that position. And use lots of items is not comfortable.

QTableWidgetItem *Type = new QTableWidgetItem;
if( line.contains("some"))
{
     Type->setText("some");
     ui->tableWidget->setItem(i, 0, Type);
}
else if( line.contains("shi"))
{
     Type->setText("shi");
     ui->tableWidget->setItem(i, 0, Type);
}
ui->tableWidget->takeItem(i, 0);
Was it helpful?

Solution

You can create copies of the item to insert at different cells. This can be done using clone :

QTableWidgetItem *Type1 = new QTableWidgetItem;

Type1->setText("some");
ui->tableWidget->setItem(row1, col1, Type1);

QTableWidgetItem *Type2 = Type1->clone(); // create a copy
Type2->setText("shi");
ui->tableWidget->setItem(row2, col2, Type2);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top