Results 1 to 2 of 2

Thread: setting multiple qstandarditems to a table model

  1. #1
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    3
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default setting multiple qstandarditems to a table model

    Hi ll
    I've been trying to send multiple items to a table row at once but with little success.

    First I tried
    Qt Code:
    1. QStandardItem *item = new QStandardItem( QString( "hello" ), QString( "world" ) );
    2. model.setItem( 0,0, item);
    To copy to clipboard, switch view to plain text mode 
    this just gives an error.

    Next I tried
    Qt Code:
    1. QStandardItem *item = new QStandardItem( QString( "hello" ) );
    2. model.setItem( 0,0, item);
    3. item->appendRow( new QStandardItem( "Wold" ) );
    4. (with or with out this line) model.setItem( 0,1, item);
    To copy to clipboard, switch view to plain text mode 
    that just puts hello in position 0,0. No world in 1,0.

    I can get it to work by doing
    Qt Code:
    1. QStandardItem *item = new QStandardItem( QString( "hello" ) );
    2. model.setItem( 0,0, item);
    3. QStandardItem *item2 = new QStandardItem( "Wold" ) );
    4. model.setItem( 0,1, item2);
    To copy to clipboard, switch view to plain text mode 


    Is there anyway where I can send a list of items to each contiguous column along the row.
    I think I'm missing something obvious .

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setting multiple qstandarditems to a table model

    There is an appendRow() overload that takes a list of items.

    If your data is really just a table, I would suggest looking into creating your own model based on QAbstractTableModel.

    List and table models are really not that hard to implement.

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 2nd November 2011, 11:13
  2. QDataWidgetMapper setting own model index
    By AlGaN in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2010, 16:34
  3. Replies: 2
    Last Post: 23rd July 2008, 17:48
  4. Replies: 1
    Last Post: 16th November 2007, 12:06
  5. QT Table Model
    By aekilic in forum Qt Programming
    Replies: 15
    Last Post: 24th January 2007, 12:57

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.