get and set qtablewidget parameters from a custom widget



  • i have a qstackwidget with different custom widgets.
    in the new_tab page i have a widget that contains a qtablewidget.

    when i press the button i execute the code below.

    ui->new_tab->show();
    ui->menu_tab->hide();
    
    QTableWidget *tbl = ui->new_tab->findChild<QTableWidget*>("table_new");
    qDebug() << tbl;
    
    tbl->setHorizontalHeaderLabels(QStringList() << "Test Type" << "Depth" << "Date & Time");
    tbl->setColumnWidth(0,100);
    tbl->setColumnWidth(1,200);
    tbl->setColumnWidth(2,300);
    
    int currentRow = tbl->rowCount();
    tbl->setRowCount(currentRow+1);
    tbl->setItem(currentRow, 0, new QTableWidgetItem("lengh"));
    tbl->setItem(currentRow, 1, new QTableWidgetItem("width"));
    tbl->setItem(currentRow, 2, new QTableWidgetItem("height"));
    

    the code compiles fine but i don't see any data added to the qtablewidget.
    what am i missing?


  • Lifetime Qt Champion

    Hi,

    Aren't you missing a setColumnCount ?



  • i set that in the designer. i have a column count of 3.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.