Results 1 to 4 of 4

Thread: how to add a complte row at a time in QTableWidget?

  1. #1
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default how to add a complte row at a time in QTableWidget?

    Hi all,

    I creating a GUI, i have collection of text files, all these files have some headers and list of number under each header( but they are not actual table).
    I want my program to read those files and whenever a user enters a file name, it must read that headers and content must display them in GUI in table format.
    I already did the reading of header and content and i can also display the header as well.
    Now i stuck with displaying content in the GUI table.

    I'm trying to do the following

    InserRow(rowNumber, Line)

    here line is QStringList.
    I dont want to keep count of collumn, as in a file fixed number of column will be there...
    How can i do that?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to add a complte row at a time in QTableWidget?

    Not sure I understood your question. See if this helps
    Qt Code:
    1. tableWidget->setColumnCount(Line.count());
    2. for(int col = 0; col < Line.count(); col++)
    3. {
    4. int row = tableWidget.rowCount();
    5. tableWidget->insertRow(row);
    6. tableWidget->setItem(row, col, new QTableWidgetItem(Line.at(col)));
    7. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Santosh Reddy for this useful post:

    aurora (16th November 2011)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to add a complte row at a time in QTableWidget?

    A for() loop?

  5. #4
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to add a complte row at a time in QTableWidget?

    Quote Originally Posted by Santosh Reddy View Post
    Not sure I understood your question. See if this helps
    Qt Code:
    1. tableWidget->setColumnCount(Line.count());
    2. for(int col = 0; col < Line.count(); col++)
    3. {
    4. int row = tableWidget.rowCount();
    5. tableWidget->insertRow(row);
    6. tableWidget->setItem(row, col, new QTableWidgetItem(Line.at(col)));
    7. }
    To copy to clipboard, switch view to plain text mode 
    Thank u santosh... i did it...


    Added after 6 minutes:


    And how can i adjust the collumn width depending on the content?
    Last edited by aurora; 16th November 2011 at 05:19.

Similar Threads

  1. Replies: 5
    Last Post: 19th November 2010, 02:25
  2. Replies: 0
    Last Post: 18th October 2010, 11:59
  3. Replies: 6
    Last Post: 18th August 2010, 12:52
  4. Replies: 2
    Last Post: 13th May 2009, 10:35
  5. QTableWidget::setItem very slow the second time
    By miraks in forum Qt Programming
    Replies: 4
    Last Post: 26th September 2008, 22:18

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.