So, what i’m using is a QTreeWidget to make a File-Tree. I can easily create the files, and folders. But the issue comes when we talk about sub-folders. For example:
Folder1
Folder1/SubFolder1
Folder1/SubFolder1/SubFolder2
How do i exactly create the sub-folders? Here’s my code to make the folders:
void Tree::addFolder(const QString &folderName)
{
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0, folderName); // Sets the text.
m_projectItem->addChild(item); // Adds it to the main path. (It's a QTreeWidgetItem)
this->expandItem(item); // Expands.
}
Would i need to create another function (something like addSubFolder) to add folders inside another folders?
I am assuming that m_projectItem is your root node.
I would implement the addFolder method similar to
Then I would implement another method which is setting up the tree by calling addFolder appropriately – referring to your example, in its simplest static form this could be
Disclaimer: I have not tested the code – I have recently implemented something similar in Python 🙂