[Solved] Add Coloumn to QTableWidgetItem



  • Hi, i have a QTableWidgetItem and i want add a special header with a data, i want only a header of the table.
    So i have made this

    @
    QTableWidgetItem *item;
    item = new QTableWidgetItem();
    item->setTextAlignment(Qt::AlignCenter);
    item->setText(QString::number(value));

    //Show In Table
    ui->table->insertColumn(Ncoloumn);
    ui->table->setHorizontalHeaderItem(Ncoloumn,item);
    Ncoloumn++;
    @

    Where Ncoloumn++ is a quint8 member of the class.

    For test i use a simple for

    @
    for(quint8 a=0;a<10;a++)
    setTableValue(a);
    @

    The problem is with this code the table is empty. I don't understand why.



  • I think you need to set the number of columns at some point.

    I have something like:
    @QTableWidget *tableWidget = new QTableWidget(this):
    int column = 10, row = 3;

    tableWidget->setColumnCount(column);
    tableWidget->setRowCount(row);

    for ( int i = 0 ; i < column ; i++)
    {
    tableWidget->setVerticalHeaderItem( i, new QTableWidgetItem(QString::number(i)) );
    for ( int j = 0 ; j < row ; j++ )
    {
    tableWidget->setItem( i, j, new QTableWidgetItem(QString::number("0")) );
    }
    }@



  • thanks for reply. solved.


Log in to reply
 

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