Qt: How to add Custom ‘Local Drive’ row in QFileSystemModel to display Drives
I am using QFileSystemModel to represent file structure through the QTreeView. Everything works fine and it displays C:, D: etc drives in TreeView, but I need to add an additional row at the beginning of the tree. For example for now is:
+ C:
+ D:
+ E:
After adding the row ‘Local Drives’ at the beginning, I wanna display it like:
Code:
- Local Drive
+ C:
+ D:
+ E:
Here is the code:
Code:
pSystemPrimaryModel = new QFileSystemModel(this);
pSystemPrimaryModel
->setRootPath
(QDir::currentPath());
ui->TreeView->setModel(pSystemPrimaryModel);
Re: Qt: How to add Custom ‘Local Drive’ row in QFileSystemModel to display Drives
Please stop spamming. One thread for the problem is enough, you don't have to post in five different threads.
1 Attachment(s)
Re: Qt: How to add Custom ‘Local Drive’ row in QFileSystemModel to display Drives
I am sorry. I tried using QFSFileEngine too but it just gives me a list of drives in 'Local Folder' but not the directories inside each drive. Can you please check and tel me whether this is a right way or not.
Code:
for(int i = 0; i < list.size(); i++)
{
qDebug() << list.at(i).absoluteDir();
}
QList<QStandardItem *> LocalItem;
LocalItem.at(0)->setEditable(false);
m_model->insertRow(0,LocalItem);
for (int i = 0; i < list.size(); i++)
{
QString str
= list.
at(i
).
absolutePath();
Localchild->setEditable(false);
LocalparentItem->appendRow(Localchild);
}
ui->PrimTreeView->setModel(m_model);
Output:
Attachment 8492
Quote:
Originally Posted by
wysota
Please stop spamming. One thread for the problem is enough, you don't have to post in five different threads.
Re: Qt: How to add Custom ‘Local Drive’ row in QFileSystemModel to display Drives
Quote:
Originally Posted by
owais_blore
I am sorry. I tried using QFSFileEngine too but it just gives me a list of drives in 'Local Folder' but not the directories inside each drive.
You are only asking for the drives, how do you expect the program to know that you want to recurse into them?
Cheers,
_
Re: Qt: How to add Custom ‘Local Drive’ row in QFileSystemModel to display Drives
Yes anda you are right. This scenario seems to be complicated. How can I make sure after clicking each drive, I should recurse into them?
Quote:
Originally Posted by
anda_skoa
You are only asking for the drives, how do you expect the program to know that you want to recurse into them?
Cheers,
_
Re: Qt: How to add Custom ‘Local Drive’ row in QFileSystemModel to display Drives
The tree view asks the model about the child count (rowCount) of each node. If the count is greater than 0 then the node will be visualized as expandable.
When the user expands that node, the view will ask for the children.
Since you are working with a model that stores all data in itself, you'll have to build the model that way, i.e. recurse through the data structure and create items accordingly.
Cheers,
_