Re: C++ Tree View operation
if you are looking for a widget you should have a look at QTreeWidget
if what you want is a data structure (but not a view to display it). You'll have to create it in a very classical way :
Code:
class TreeNode
{
public:
// methods here
private:
TreeNode *m_parent;
QList<TreeNode*> m_children;
};
managing the hierarchy of such a structure is quite straightforward but you need to be careful about memory leaks (yeah, the node class MUST be allocated dynamically and used through pointers, there is no alternative).
Re: C++ Tree View operation
thank for reply .. but i show... there are problem to show this ????
Re: C++ Tree View operation
Sorry I really don't understand what you mean...
If you just want a ready-to-use tree structure that you can display in a couple of lines than QTreeWidget is definitely the right choice.
If you want to create your own low-level tree structure you can use the skeleton I showed you. To display that you will have to create a custom model and set it to a QTreeView. The tree model example is a pretty good start for that.
Re: C++ Tree View operation
fullmetalcoder oyu are my hero !!
the example is perfect. on that basis I would like to add a node, delete a parent node with all children, add a child to a father. I can do it right?
Re: C++ Tree View operation
Quote:
Originally Posted by
zeeb100
fullmetalcoder oyu are my hero !!
My pleasure. :) If my answer did spare you some headbanging and hours of frustration consider using that shiny "thanks" button below the posts ;)
Quote:
Originally Posted by
zeeb100
on that basis I would like to add a node, delete a parent node with all children, add a child to a father. I can do it right?
Sure you can. Once you have added proper methods to your node class adding/removing children is child's play. e.g :
Code:
class TreeNode
{
public:
~TreeNode()
{
qDeleteAll(m_children);
}
void appendChild(TreeNode *c)
{
m_children.append(c);
}
void removeChild(int row)
{
m_children.removeAt(row);
}
void deleteChildRecursively(int row)
{
TreeNode *c = m_children.takeAt(row);
delete c;
}
private:
TreeNode *m_parent;
QList<TreeNode*> m_children;
};
Please not that the above code is just a skeleton which won't work as is (it does not deal with model/view updating for instance, which is described in the example I refered to in my previous post).
Re: C++ Tree View operation
:eek::( it's really hard :s
Re: C++ Tree View operation
Yeah, model/view is a bit hard to master but hopefully the tutorials are quite good.
If you need more example of custom tree model you can have a look at those I have created for use in Edyuk : https://edyuk.svn.sf.net/svnroot/edy...projectmodel2/ and https://edyuk.svn.sf.net/svnroot/edy...y/qcodemodel2/
They are not very documented but the code is clean enough to serve as an example.
Re: C++ Tree View operation
now i use the struct of exemple tree view ok ... but i don't do the this function
Code:
class TreeNode
{
public:
~TreeNode()
{
qDeleteAll(m_children);
}
void appendChild(TreeNode *c)
{
m_children.append(c);
}
void removeChild(int row)
{
m_children.removeAt(row);
}
void deleteChildRecursively(int row)
{
TreeNode *c = m_children.takeAt(row);
delete c;
}
private:
TreeNode *m_parent;
QList<TreeNode*> m_children;
};
how can access item of model ???
example
insert a child in the parent specify
Code:
parent_z
child1
child2
......
insert(child3) into parent_z
......
parent_z
child1
child2
child3
Re: C++ Tree View operation
i ok there are successful. but the function ~TreeItem (); it does not eliminate the node because if I execute row count the same value returns always
i use the The tree model example