Results 1 to 9 of 9

Thread: read QTableWidget cells

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    Finland
    Posts
    63
    Thanks
    1
    Thanked 22 Times in 19 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: read QTableWidget cells

    john_god, how your example differs from Rewo's example, those seems to be same?

    The issue where you should be careful is that if the cell does not have item the item()-method returns NULL which means that you should check the validity of the pointer before accessing cell's content. That said this is implementation issue, if you implement your table in a way that there is always item in every cell then this kind of check is not needed. Next is a common pattern in my own table related handling methods:

    Qt Code:
    1. QTableWidgetItem *itab = tableWidget->item(0,0);
    2. if (itab) {
    3. QString itabtext = itab->text();
    4. :
    5. :
    6. }
    To copy to clipboard, switch view to plain text mode 

  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: read QTableWidget cells

    in the end, it's the same, but I'm simplifying code by eliminating itab an reading directly from item.

    I agree with wath you said about cell validation, to me its all correct.

    Just a side note, for writing cell content I usually do a pattern like this:

    Qt Code:
    1. if (tableWidget->item(i,j) == 0)
    2. {
    3.  
    4. QTableWidgetItem *newItem = new QTableWidgetItem("some text");
    5. tableWidget->setItem(i,j, newItem);
    6. }
    7. else
    8. {
    9. tableWidgetMatrix->item(i, j)->setText("some text");
    10. }
    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. Merging cells in QTableWidget
    By lyucs in forum Newbie
    Replies: 1
    Last Post: 22nd January 2010, 19:15
  2. Filling empty cells in QTableWidget
    By lyucs in forum Newbie
    Replies: 2
    Last Post: 20th October 2009, 17:12
  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.