Results 1 to 3 of 3

Thread: Quick Question:Why my TableView appears blank?!

  1. #1
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Quick Question:Why my TableView appears blank?!

    Qt Code:
    1. MyDialog::MyDialog(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. QStandardItemModel model(4, 2);
    5. tableView = new QTableView(this);
    6. tableView->setModel(&model);
    7.  
    8. ComboBoxDelegate delegate;
    9. tableView->setItemDelegateForColumn(1,&delegate);
    10.  
    11. for (int row = 0; row < 4; ++row) {
    12. for (int column = 0; column < 2; ++column) {
    13. QModelIndex index = model.index(row, column, QModelIndex());
    14. model.setData(index, QVariant((row+1) * (column+1)));
    15. }
    16. }
    17. view2 = new QTableView(this);
    18. view2->setModel(&model);
    19. view2->setItemDelegateForColumn(1,&delegate);
    20.  
    21. for (int row = 0; row < 4; ++row) {
    22. for (int column = 0; column < 2; ++column) {
    23. QModelIndex index = model->index(row, column, QModelIndex());
    24. model->setData(index, QVariant((row+1) * (column+1)));
    25. }
    26. }
    27.  
    28. vboxlayout = new QVBoxLayout(this);
    29. vboxlayout->addWidget(tableView);
    30. vboxlayout->addWidget(view2);
    31.  
    32. setLayout(vboxlayout);
    33. }
    To copy to clipboard, switch view to plain text mode 


    Added after 1 12 minutes:


    found it!!

    In the header file I have:
    Qt Code:
    1. private:
    To copy to clipboard, switch view to plain text mode 

    In the source I had written:

    Qt Code:
    1. QStandardItemModel model(4, 2);
    2. tableView->setModel(&model);
    To copy to clipboard, switch view to plain text mode 

    BUT it should be:


    Qt Code:
    1. model = new QStandardItemModel(4, 2);
    2. tableView->setModel(model);
    To copy to clipboard, switch view to plain text mode 
    Last edited by fatecasino; 4th March 2011 at 00:00.

  2. #2
    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: Quick Question:Why my TableView appears blank?!

    You have the same problem with your ComboBoxDelegate going out of scope at the end of the constructor.

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

    fatecasino (4th March 2011)

  4. #3
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Quick Question:Why my TableView appears blank?!

    You have the same problem with your ComboBoxDelegate going out of scope at the end of the constructor.
    you are totally right!

Similar Threads

  1. Quick Bindvalue Question
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 6th February 2009, 21:09
  2. Quick question: infinite double?
    By Raccoon29 in forum Qt Programming
    Replies: 2
    Last Post: 17th October 2008, 15:05
  3. Quick RegExp question
    By stealth86 in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2007, 08:23
  4. Quick Question on QSqlQuerry
    By locus in forum Qt Programming
    Replies: 1
    Last Post: 13th March 2007, 14:53
  5. Quick spacing question
    By bruccutler in forum Newbie
    Replies: 4
    Last Post: 8th March 2007, 20:46

Tags for this Thread

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.