[Interest] Model for QTreeView

Alex Strickland sscc at mweb.co.za
Mon Nov 19 15:41:06 CET 2012


Hi

I am trying to create a workable example of a very simple model to use 
with a QTreeView. Here is the underlying hierarchical data:

TreeModel::TreeModel()
{
     TreeStruct treeStruct;

     treeStruct.name = "one";
     treeStruct.leaves << "one/one" << "one/two";
     m_treeData << treeStruct;

     treeStruct.name = "two";
     treeStruct.leaves.clear();
     m_treeData << treeStruct;

     treeStruct.name = "three";
     treeStruct.leaves << "three/one" << "three/two" << "three/three";
     m_treeData << treeStruct;
}

or:
	one
		one/one
		one/two
	two
	three
		three/one
		three/two
		three/three

Can someone tell me what the index() override would be:

QModelIndex TreeModel::index(int row,
                              int column,
                              const QModelIndex &parent) const
{
	// huh?
}

Perhaps that would be enough to allow me to work out the rest. In 
essence I cannot seem to grasp how QModelIndex works.

-- 
Regards
Alex



More information about the Interest mailing list