Results 1 to 5 of 5

Thread: On subclassing QStandardItem and displaying different stuff

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11
    Wiki edits
    1

    Default Re: On subclassing QStandardItem and displaying different stuff

    Thanks for your reply, but I think I need a little more detail.
    Can I use QListView for this? (two items on the same row?)

    And when I add a item with the label A, should I create a child item to that item, and set the runnig time to it?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,319
    Thanks
    316
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: On subclassing QStandardItem and displaying different stuff

    Here's an example. One thing to note, which may be why you are having a problem in the first place: QListView only supports *one* column. If you want more than one column, you need to use QTableView or QTreeView.

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QTableView>
    3. #include <QStandardItemModel>
    4. #include <QList>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9. QTableView view;
    10.  
    11.  
    12. model.setColumnCount( 2 );
    13.  
    14. QStandardItem * item;
    15. for ( int nItem = 0; nItem < 10; ++nItem )
    16. {
    17. QList< QStandardItem * > items;
    18.  
    19. items << new QStandardItem( QString( 'A' + nItem ) );
    20. items << new QStandardItem( QString::number( nItem * 10 + 10 ) );
    21. model.appendRow( items );
    22. }
    23.  
    24. view.setModel( &model );
    25. view.show();
    26. return a.exec();
    27. }
    To copy to clipboard, switch view to plain text mode 

    The attached screnshots show table and tree views; all I did was change the view type from QTableView to QTreeView.

    Table.png Tree.png
    Last edited by d_stranz; 20th November 2011 at 00:04.

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

    Gunnar (20th November 2011)

  4. #3
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11
    Wiki edits
    1

    Default Re: On subclassing QStandardItem and displaying different stuff

    Thank you. That cleared out a few issues.

Similar Threads

  1. Phonon stuff
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 31st August 2009, 12:26
  2. Get Hot New Stuff!!!!
    By Mystical Groovy in forum KDE Forum
    Replies: 4
    Last Post: 16th December 2008, 00:21
  3. adding PHONON and stuff
    By baray98 in forum Installation and Deployment
    Replies: 1
    Last Post: 18th August 2008, 17:37
  4. Subclassing QStandardItem
    By aLiNuSh in forum Newbie
    Replies: 4
    Last Post: 5th April 2007, 20:00
  5. Howto draw stuff
    By Morea in forum Newbie
    Replies: 16
    Last Post: 7th April 2006, 12:05

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