When one U disk was plugged in system , it shows in the QTreeView by QFileSystemModel as root .
The method is to hide other partitions expcet the U disk's . Like attached picture.
like this:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
model = new QFileSystemModel;
//model->setRootPath("/");
model->setRootPath("d:");
listView = new QTreeView;
listView->setModel(model);
listView->show();
QModelIndex root = model->index("d:", 0);
for (int i=67; i<=90; i++) {
QChar ch(i);
QString str(ch);
str+=":";
qDebug() << str;
QModelIndex node = model->index(str, 0);
if (node==root) continue;
for (int j=1; j<26; j++) {
//listView->setRowHidden(0, node.parent(), true); // OK
listView->setRowHidden(j, node.parent(), true); // OK
}
}
}
But when one U disks was plugged in system , how to show them like this style? Just show these U disks partitions in the QTreeView , and all as root.
I have tried the upper method , but failed .
Bookmarks