April 21, 2011

stuk stuk
Ant Farmer
560 posts

[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

  1. item = new QTableWidgetItem();
  2. item->setTextAlignment(Qt::AlignCenter);
  3. item->setText(QString::number(value));
  4.  
  5. //Show In Table
  6. ui->table->insertColumn(Ncoloumn);
  7. ui->table->setHorizontalHeaderItem(Ncoloumn,item);
  8. Ncoloumn++;

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

For test i use a simple for

  1. for(quint8 a=0;a<10;a++)
  2.         setTableValue(a);

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

2 replies

April 22, 2011

Thrichard Thrichard
Lab Rat
2 posts

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

I have something like:

  1. QTableWidget *tableWidget = new QTableWidget(this):
  2. int column = 10, row = 3;
  3.  
  4. tableWidget->setColumnCount(column);
  5. tableWidget->setRowCount(row);
  6.  
  7. for ( int i = 0 ; i < column ; i++)
  8. {
  9.    tableWidget->setVerticalHeaderItem( i, new QTableWidgetItem(QString::number(i)) );
  10.    for ( int j = 0 ; j < row ; j++ )
  11.    {
  12.       tableWidget->setItem( i, j, new QTableWidgetItem(QString::number("0")) );
  13.    }
  14. }

April 27, 2011

stuk stuk
Ant Farmer
560 posts

thanks for reply. solved.

 
  ‹‹ Phonon::VideoPlayer does not display video      Problem with QSqlTableModel ››

You must log in to post a reply. Not a member yet? Register here!