Results 1 to 18 of 18

Thread: adding items in qtablewidget

  1. #1
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default adding items in qtablewidget

    Hi, I am having problems to show cells in my qtablewidget. These are parts of code that I use to implement qtablewidgetitems:


    tableTestSuits->setRowCount(0); // tableTestSuits is QTablewidget *

    for (unsigned j=0; j<vTestCaseResults.size();j++)
    {
    .......
    QTableWidgetItem *item=new QTableWidgetItem (tr(tempName.toLatin1()));
    QTableWidgetItem *item3=new QTableWidgetItem (tr(tempVersion.toLatin1()));
    QTableWidgetItem *item5=new QTableWidgetItem (tr(tempResult.toLatin1()));
    QTableWidgetItem *item2=new QTableWidgetItem (tr(tempDate.toLatin1()));
    QTableWidgetItem *item4=new QTableWidgetItem (tr(tempDuration.toLatin1()));
    tableTestSuits->insertRow(j);
    tableTestSuits->setItem(j,0,item2);
    tableTestSuits->setItem(j,3,item4);
    tableTestSuits->setItem(j,4,item5);
    tableTestSuits->setItem(j,1,item3);
    tableTestSuits->setItem(j,2,item);
    }

    I am pretty sure that strings for qtablewidgetitems are ok. So, there must be something else wrong, but I don't know what. Any suggestions welcomed.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: adding items in qtablewidget

    What value did you set the columnCount to?

  3. #3
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: adding items in qtablewidget

    I set it to 5

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: adding items in qtablewidget

    OK, do you see row and column labels on the table headers?

  5. #5
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: adding items in qtablewidget

    I see solumn headers, yes, but row headers no, because I've hide it with verticalHeader()->hide() method.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: adding items in qtablewidget

    Quote Originally Posted by Djony View Post
    I see solumn headers, yes, but row headers no, because I've hide it with verticalHeader()->hide() method.
    Can you see them, if you comment out that line?

  7. #7
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: adding items in qtablewidget

    yes, I can see them.

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: adding items in qtablewidget

    I'd still suspect the problem is with those strings. What happens if you replace:
    Qt Code:
    1. QTableWidgetItem *item=new QTableWidgetItem (tr(tempName.toLatin1()));
    To copy to clipboard, switch view to plain text mode 
    with something like
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    ?
    J-P Nurmi

  9. #9
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: adding items in qtablewidget

    I tried your stuff and it doesn't work, but found out very odd thing.

    When I replace j with zero (that means this code):

    tableTestSuits->insertRow(0);

    tableTestSuits->setItem(0,0,item2);
    tableTestSuits->setItem(0,3,item4);
    tableTestSuits->setItem(0,4,item5);
    tableTestSuits->setItem(0,1,item3);
    tableTestSuits->setItem(0,2,item);
    -----------------------------------------------

    I get cell properly. I found this very odd. Have any ideas about it?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: adding items in qtablewidget

    Quote Originally Posted by Djony View Post
    When I replace j with zero [...] I get cell properly. I found this very odd. Have any ideas about it?
    What is the value of "j" just before the insertRow() line?

  11. #11
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: adding items in qtablewidget

    j is parameter of for loop. Look my first post on this topic

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: adding items in qtablewidget

    Quote Originally Posted by Djony View Post
    j is parameter of for loop. Look my first post on this topic
    I see it, but there's also "......." in the beginning of the loop body --- maybe you do something with it there?

  13. #13
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: adding items in qtablewidget

    No, I don't do anything with it. Just use for indexing. Still, have no idea. Very odd...

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: adding items in qtablewidget

    Does this work on your system?
    Qt Code:
    1. #include <QApplication>
    2. #include <QTableWidget>
    3.  
    4. const int nRows = 10;
    5. const int nCols = 10;
    6.  
    7. int main( int argc, char **argv )
    8. {
    9. QApplication app( argc, argv );
    10.  
    11. tw.setColumnCount( nCols );
    12.  
    13. for( int i = 0; i < nRows; ++i ) {
    14. tw.insertRow( i );
    15. for( int j = 0; j < nCols; ++j ) {
    16. QTableWidgetItem *item = new QTableWidgetItem( QString("(%1,%2)").arg(i).arg(j));
    17. tw.setItem( i, j, item );
    18. }
    19. }
    20.  
    21. tw.show();
    22.  
    23. return app.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

  15. #15
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: adding items in qtablewidget

    Yes, it runs OK. Funny, though, I've noticed some other things about my code for qtablewidget. For some iterations, qtablewidgets prints ok, and for some input not. I understand that strings are most suspicious, but, i've printed them with cout in console, and they are OK, just as they should be. Plus, if I just replace j with zero, code runs well. If I changed just index of rows, then strings aren't problem. Am I wright?

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: adding items in qtablewidget

    Quote Originally Posted by Djony View Post
    but, i've printed them with cout in console, and they are OK,
    What did you try to print exactly? "tr(tempName.toLatin1())" or only "tempName"?

  17. #17
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: adding items in qtablewidget

    i've printed tempName.toStdString()

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: adding items in qtablewidget

    Then try printing tr(tempName.toLatin1()).toStdString(). Maybe it gets translated to an empty string?

Similar Threads

  1. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 13:20
  2. Limitation when adding more than 256 items to a model
    By darkadept in forum Qt Programming
    Replies: 5
    Last Post: 25th May 2006, 16:26
  3. [Qt4]: Adding centered items in QListWidget
    By Jojo in forum Qt Programming
    Replies: 4
    Last Post: 16th March 2006, 21:04
  4. Adding tooltips to canvas items
    By jnana in forum Qt Programming
    Replies: 2
    Last Post: 2nd March 2006, 11:53
  5. [QT3] QComboBox: Disable adding items on Enter-keypress
    By BrainB0ne in forum Qt Programming
    Replies: 7
    Last Post: 14th January 2006, 20: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.