如何从QTableWidget::setCellWidget()中获取文本

How to get the text from QTableWidget::setCellWidget()

本文关键字:获取 取文本 setCellWidget QTableWidget      更新时间:2023-10-16

我正试图弄清楚如何从setCellWidget中获取QLabel文本。

我把我的tableWidget设置成这样:

    QLabel *nt = new QLabel();
    nt->setStyleSheet("QLabel {padding-left:1px;color: white!important;display: block;float: left;border-radius: 11px;font-weight: bold!important;border: 2px solid #FFFFFF;box-shadow: 1px 1px 2px #999999;background: #d675a7;background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #f48282, stop: 1 #d00a0a);}");
    nt->setText("1");
    nt->setFixedWidth(22);
    nt->setFixedHeight(22);
    ui->tableWidget_3->setCellWidget(0,3,nt);

我正在尝试检索这样的值:

qDebug() << ui->tableWidget_3->item(0, 3)->text();

有什么想法吗?

ui->tableWidget_3->cellWidget(0, 3)->property("text").toString();