Search code examples
c++qtqtablewidgetitem

How to add QLabel to QTableWidgetItem?


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.


Solution

  • You need to make the item editable as follows:

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