Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

[SOLVED] Questions about creating a mini file browser.

$
0
0
What i want to achieve is a mini file browser like this which shows only folders and .mp3 files So until now i have achieved someting like these: With this code: void MainWindow::on_files_path_textChanged(const QString &path) {     if(path.isEmpty() || !QDir(path).exists())         return;       //we want the path to always end with a "/". Also we want to see if the user     //just deleted a trailing "/", if so do not take actions.     if(path.right(1)!="\\" && path.right(1)!="/")     {         if(currentPath.left(currentPath.count()-1)==path)             return;         currentPath=QDir::toNativeSeparators(path+"/");     }     else     {         if(currentPath==path)             return;         currentPath=path;     }       updateFilesListWidget();       //monitor the path for any possible change at it's subfolders/audio files     if(watchFolders_)         delete watchFolders_;     watchFolders_ = new QFileSystemWatcher(this);     connect(watchFolders_, SIGNAL(directoryChanged(QString)), this, SLOT(updateFilesListWidget()));       if(currentPath.count()!=3)         settings.setValue("current_path", currentPath.left(currentPath.count()-1));     else //for hard drives we want to save them as c:/ not as c:         settings.setValue("current_path", currentPath.left(currentPath.count())); }   void MainWindow::updateFilesListWidget() {     QDir dir(ui->files_path->text());       ui->files_listWidget->clear();       QStringList list_of_subfolders = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);     for(int i=0; i<list_of_subfolders.count(); i++)     {         QListWidgetItem *folder = new QListWidgetItem;         folder->setText(list_of_subfolders.at(i));         folder->setIcon(QIcon::fromTheme("folder", QIcon(":/icons/Pictures/folder_icon.png")));         ui->files_listWidget->addItem(folder);     }       QStringList list_of_audio_files = dir.entryList(QStringList("*.mp3"), QDir::Files ,QDir::Name);     for(int i=0; i<list_of_audio_files.count(); i++)     {         QListWidgetItem *audio_file = new QListWidgetItem;         audio_file->setText(list_of_audio_files.at(i));         audio_file->setIcon(QIcon::fromTheme("audio-x-generic", QIcon(":/icons/Pictures/audio_icon.png")));         ui->files_listWidget->addItem(audio_file);     } }   void MainWindow::on_files_listWidget_itemDoubleClicked(QListWidgetItem *item) {     ui->files_path->setText(currentPath+item->text()); } My problem here, is that i am using a folder/audio icon of mine, and not using system’s default and generally this seems a bad way to do a file browser… i tried with QFileSystemModel *model = new QFileSystemModel;     model->setNameFilters(QStringList("*.mp3"));     model->setNameFilterDisables(false);     model->setRootPath(path);     ui->treeView->setModel(model);     ui->treeView->setRootIndex(model->index(path)); which creates this but i don’t know how to hide the Size/Type/Date Modified and also the triangle to show the subfolders of this folder..

Viewing all articles
Browse latest Browse all 13965

Trending Articles