owais_blore
7th December 2012, 08:12
I had asked the question about displaying Filesystem inside a treeview in such a way where local drives and removable drive get displayed under a root node - Local Drivess & Removable Drives.
QStandardItemModel *m_model = new QStandardItemModel(0,0);
pSystemPrimaryModel = new QFileSystemModel(this);
pSystemPrimaryModel->setRootPath(QDir::currentPath());
pSystemPrimaryModel->setFilter( QDir::AllDirs | QDir::NoDotAndDotDot );
QList<QStandardItem *> LocalItem;
LocalItem.insert(0,new QStandardItem("Local Drives"));
LocalItem.at(0)->setEditable(false);
m_model->insertRow(0,LocalItem);
QStandardItem* Localchild = new QStandardItem();
QStandardItem* LocalparentItem = m_model->item(0,0);
LocalparentItem->appendRow(Localchild);
ui->PrimTreeView->setModel(m_model);
This displays output with only Local Drives and no drives under it since I am not setting pSystemPrimaryModel in setModel.
8483
I wanna display the drives which are shown towards the bottom side of image under this "Local Drives" node which QFileSystemModel displays when used like this:
pSystemPrimaryModel = new QFileSystemModel(this);
pSystemPrimaryModel->setRootPath(QDir::currentPath());
ui->PrimTreeView->setModel(pSystemPrimaryModel);
QStandardItemModel *m_model = new QStandardItemModel(0,0);
pSystemPrimaryModel = new QFileSystemModel(this);
pSystemPrimaryModel->setRootPath(QDir::currentPath());
pSystemPrimaryModel->setFilter( QDir::AllDirs | QDir::NoDotAndDotDot );
QList<QStandardItem *> LocalItem;
LocalItem.insert(0,new QStandardItem("Local Drives"));
LocalItem.at(0)->setEditable(false);
m_model->insertRow(0,LocalItem);
QStandardItem* Localchild = new QStandardItem();
QStandardItem* LocalparentItem = m_model->item(0,0);
LocalparentItem->appendRow(Localchild);
ui->PrimTreeView->setModel(m_model);
This displays output with only Local Drives and no drives under it since I am not setting pSystemPrimaryModel in setModel.
8483
I wanna display the drives which are shown towards the bottom side of image under this "Local Drives" node which QFileSystemModel displays when used like this:
pSystemPrimaryModel = new QFileSystemModel(this);
pSystemPrimaryModel->setRootPath(QDir::currentPath());
ui->PrimTreeView->setModel(pSystemPrimaryModel);