PDA

View Full Version : qtreeview - subitems don't



polrus
27th November 2010, 22:02
Hello

I'm trying to use appendRow to create the following structure with 2 columns
Items in column called "group" can have children.

I can do it ok for "group" column - but i have troubles adding "cost" column values



|group | costs
------------------------------

Peter | 10

Family 1 | 55
--------John | 15
--------Jack | 20
--------Amie | 20

Paul | 15

I hope the structure is clear.
I don't have troubles adding the cost for "peter" nor Paul but I don't know how to add a second column value for the members of "Family 1"
when I have


QList<QStandardItem *> items;
items << costs_for_john_item;
john_item->appendColumn(items);


it creates another subrow for John and does not enter the second column at all.

by model.setData using row and column numbers I can't edit any value for members of Family 1 group howeveer it works for Peter, John and "family 1" and their costs.

any advices?

franz
28th November 2010, 18:27
Could you post a compilable example so we can identify the problem more easily? The code you posted is rather terse. Also, instead of the quote tag, you should use the code tag if you post code.

polrus
2nd December 2010, 20:48
QList<QStandardItem *> items,items2;

model_drzewa= new QStandardItemModel;

QStandardItem *z1_1 = new QStandardItem( "Peter" );
QStandardItem *z1_2 = new QStandardItem( "Family" );
QStandardItem *z1_3 = new QStandardItem( "Paul" );
QStandardItem *z2_1 = new QStandardItem( "John" );
QStandardItem *z2_2 = new QStandardItem( "Jack" );
QStandardItem *z2_3 = new QStandardItem( "Amie" );
QStandardItem *z1_1_costs = new QStandardItem( "first 1 costs" );
QStandardItem *z2_1_costs = new QStandardItem( "second 1 costs" );

model_drzewa->invisibleRootItem()->appendRow(z1_1);
model_drzewa->invisibleRootItem()->appendRow(z1_2);
z1_2->appendRow(z2_1);
z1_2->appendRow(z2_2);
z1_2->appendRow(z2_3);

items <<z2_1_costs;
z2_1->appendColumn(items); //why does it create another subitem instead of a parallel column ?


model_drzewa->invisibleRootItem()->appendRow(z1_3);
model_drzewa->setHorizontalHeaderLabels( QStringList() << "Zlecenia" << "costs" );
ui->treeView->setModel(model_drzewa);
ui->treeView->expandAll();
ui->treeView->model()->setData(ui->treeView->model()->index(0,1),QVariant("first 1 costs wariant"));

ui->treeView->model()->setData(ui->treeView->model()->index(0,1).child(0,0),QVariant ("testing if i can change it like that"));
//no i can't

and the effect is http://pksiazki.com.pl/seba/linux/qtreeview_problem.jpeg

instead I would expect "second 1 costs" to be in parallel with John in the second column

Lykurg
2nd December 2010, 21:08
See QStandardItemModel::setItem().