PDA

View Full Version : Using QAbstractItemView



GrahamLabdon
2nd March 2011, 15:18
Hi
I have a data structure that looks like (this will grow)

Identity
Location (string)
Name (string)
Company (string)
Tool Type (enumeration)
Configuration
Spacing (int)
Offset (int)
Reference (int)

I have a struct to store these values.
I want to display this in a QTreeView to allow the suer to edit them.
To this end I created a subclass of QAbstractItemModel but am now having problems implementing the virtual methods. For example i cant figure out what to do in the index() method.
I am wrong to use QAbstractItemModel ?
Is there a better way?

TIA

Graham
Additional Information

wysota
2nd March 2011, 15:33
If you don't feel comfortable with implementing your own model, use QStandardItemModel.

GrahamLabdon
2nd March 2011, 16:04
Thanks for your reply
As a first attempt I did this


QStandardItemModel model;
QStandardItem *parentItem = model.invisibleRootItem();
for (int i = 0; i < 4; ++i) {
QStandardItem *item = new QStandardItem(QString("item %0").arg(i));
parentItem->appendRow(item);
parentItem = item;
}

QTreeView *treeView = new QTreeView(this);
treeView->setModel(&model);

The treeView is displayed but contains no data

what might I have missed

Graham

wysota
2nd March 2011, 16:51
Your model goes out of scope.