Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Add Coloumn to QTableWidgetItem

[Solved] Add Coloumn to QTableWidgetItem

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 10.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stukdev
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Thrichard
      wrote on last edited by
      #2

      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")) );
      }
      }@

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stukdev
        wrote on last edited by
        #3

        thanks for reply. solved.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved