PDA

View Full Version : QModelIndex : Selection of items with expandable items in QTreeView



Saptarshi4031
19th August 2010, 11:58
Hi,

A treemodel is used to display a structure in hierarchical format in QTreeView. The item Checked in the TreeView has to be displayed in a TextBox.

I am using selectionChanged () as the signal and it passess ModelIndex of the selected item to the slot function.

The problem is that ModelIndex I can get the row count and the column count (which is zero here).But the count is localized to a specific parent.My problem is that I want a unique representation of the item selected whether be it a parent or child.But what I get is sometimes only the parent string data is accessible sometimes the child.


void function_slot(QItemSelection &arg,QItemSelection &m)
{
Model *model;
QModelIndex index,k;
int row;


QModelIndexList selected =arg.indexes();
row=index.row();
foreach(index,selected)
{
if(index.isValid())
{
row=index.row();
k=model->index(row,0);
qDebug<< model->data(l,Qt::DisplayRole).toString();
}
}
}

peterius
19th August 2010, 21:08
You mean there's multiple parents so the rows aren't unique?

Saptarshi4031
20th August 2010, 05:18
Yes, each row has a parent ,whose child in turn is another parent ..likewise