Results 1 to 2 of 2

Thread: fill cells in a tableWidget

  1. #1
    Join Date
    Aug 2009
    Posts
    3

    Default fill cells in a tableWidget

    hi..

    I'm starting with Qt

    I don't know how can I fil a TableWidget with values.

    Can u help me?

    thanks....

  2. #2
    Join Date
    Jan 2006
    Location
    Innsbruck, Austria
    Posts
    62
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: fill cells in a tableWidget

    As the documentation states:

    Items are created ouside the table (with no parent widget) and inserted into the table with setItem():
    Qt Code:
    1. QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg(
    2. (row+1)*(column+1)));
    3. tableWidget->setItem(row, column, newItem);
    To copy to clipboard, switch view to plain text mode 

    First you have to specify how many rows and columns should the table have using setRowCount() and setColumnCount().

    Example:

    Qt Code:
    1. tableWidget->setRowCount(10);
    2. tableWidget->setColumnCount(3);
    3.  
    4. for(int row = 0; row < 10; row++) {
    5. for(int column = 0; column < 3; column++) {
    6. QString text = QString::number(row) + "," + QString::number(column);
    7. tableWidget->setItem(row, column, item);
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. tableWidget created in Qt Creator not updated
    By binaural in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2009, 21:50
  2. Fill mode using QPainter
    By lni in forum Qt Programming
    Replies: 7
    Last Post: 23rd March 2009, 18:03
  3. Lists/multiline text in QTableView cells
    By dv_ in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2008, 23:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.