How to add QLabel to QTableWidgetItem?

1.7k Views Asked by At

I do this like that :

QLabel *qlab = new QLabel;
ui->tableWidget->setColumnCount(3);
ui->tableWidget->setRowCount(1);
ui->tableWidget->setCellWidget(0, 0, qlab);

but nothing happen when i click on cell and i can't write text.

1

There are 1 best solutions below

0
On BEST ANSWER

You need to make the item editable as follows:

QTableWidgetItem *tableWidgetItem = ui->tableWidget->item(0, 0);
tableWidgetItem->setFlags(tableWidgetItem->flags() | Qt::ItemIsEditable);