PDA

View Full Version : QTreeWidget how to's



bruccutler
6th March 2007, 01:12
I'm starting to put together a tree control. I need to know if I can use the same pointer to allocate the tree nodes, or if I need to keep separate variables around for each tree node?

Example:

if (pConn)
{
while (pConn[i].name != NULL)
{
QTreeWidgetItem *subItem = new QTreeWidgetItem(m_pConnectionsItem, ITEM_CONNECTIONS);
subItem->setText(pConn[i].name);
i++;
}
}

Do I need separate subItems, one for each sub-item in the tree? What is the right way to do this? Does someone have some sample working code I could look at?
- BRC

patrik08
6th March 2007, 02:02
I'm starting to put together a tree control. I need to
Do I need separate subItems, one for each sub-item in the tree? What is the right way to do this? Does someone have some sample working code I could look at?
- BRC

http://doc.trolltech.com/4.0/itemviews-simpletreemodel.html

On your qt installation path have a look on xml tree sample..... /example/ /demo/

smacchia
6th March 2007, 13:47
You need to allocate a QTreeWidgetItem instance for each node in the list. Once it is inserted in the tree, the memory is owned by Qt. Only if you call ::takeItem on the tree will you again own the memory of the item that you "take" (hence it is your responsibility to free it unless you re-insert it into the tree).

But, you don't need to keep variables to the items around, unless you intend to manipulate them for some reason. And even in that case, you no longer own the memory unless you invoke ::takeItem on the tree.

HTH,
Susan

bruccutler
6th March 2007, 17:23
I have another question about tables:
I want to be able to set an entire row all at once. As far as I can determine I have to set each individual cell one at a time.

How do I or can I, set an entire row all at once, perhaps with a StringList?
- BRC