Results 1 to 7 of 7

Thread: [How to ?] Writing QTableWidget cells.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    19
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [How to ?] Writing QTableWidget cells.

    Thanks, it helped. But I have one more problem.

    I tried to apply that:

    Qt Code:
    1. itab -> setText("X");
    2. for(int a=0;a<irows;a++)
    3. for(int b=0;b<icols;b++) {
    4. tableWidget->setItem(a, b, itab);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Filling "X" works only for (0,0) cell, while running program, there is statement in compiling console:

    "QTableWidget: cannot insert an item that is already owned by another QTableWidget"

    If I have 4x3 table, this statement appears 4x3-1=11 times.

    I tried to make an "itab" array, but it failed.

    I think that itab needs some release from cell, but dunno how to do that.

    ________

    EDIT 2 minutes later:

    I did that:


    Qt Code:
    1. for(int a=0;a<irows;a++)
    2. for(int b=0;b<icols;b++) {
    3. itab -> setText("X");
    4. tableWidget->setItem(a, b, itab);
    5. }
    To copy to clipboard, switch view to plain text mode 

    And it works for me .

  2. #2
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: [How to ?] Writing QTableWidget cells.

    Please let me make a sugestion, if you plan to fill the table more than once, use the following code to avoid duplicating items

    Qt Code:
    1. for(int a=0;a<irows;a++)
    2. for(int b=0;b<icols;b++){
    3.  
    4. if (tableWidget->itab(a,b) == 0)
    5. {
    6. itab->setText("X");
    7. tableWidget->setItem(a,b, itab);
    8. }
    9. else
    10. {
    11. tableWidget->item(a, b)->setText("X");
    12. }
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

Similar Threads

  1. read QTableWidget cells
    By navid in forum Newbie
    Replies: 8
    Last Post: 4th April 2010, 10:40
  2. Merging cells in QTableWidget
    By lyucs in forum Newbie
    Replies: 1
    Last Post: 22nd January 2010, 19:15
  3. Focus of cells in a QTableWidget
    By SailinShoes in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2008, 08:19
  4. QTableWidget, header cells margin
    By DpoHro in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2008, 23:38
  5. QTableWidget with overlapping cells (span)
    By rhi in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2006, 18:44

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
  •  
Qt is a trademark of The Qt Company.