PDA

View Full Version : setting multiple qstandarditems to a table model



knobby67
16th August 2014, 11:41
Hi ll
I've been trying to send multiple items to a table row at once but with little success.

First I tried


QStandardItem *item = new QStandardItem( QString( "hello" ), QString( "world" ) );
model.setItem( 0,0, item);

this just gives an error.

Next I tried


QStandardItem *item = new QStandardItem( QString( "hello" ) );
model.setItem( 0,0, item);
item->appendRow( new QStandardItem( "Wold" ) );
(with or with out this line) model.setItem( 0,1, item);

that just puts hello in position 0,0. No world in 1,0.

I can get it to work by doing


QStandardItem *item = new QStandardItem( QString( "hello" ) );
model.setItem( 0,0, item);
QStandardItem *item2 = new QStandardItem( "Wold" ) );
model.setItem( 0,1, item2);



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 :D.

Thanks in advance

anda_skoa
16th August 2014, 11:55
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,
_