How to display Details of Audio File in QTreeView



  • I need to display details of all .mp3 files present in my drives. I am using QTreeView to display. Here is the code:
    @ // Displays Files in Detail View on Clicking Drive
    void DetailView::on_DriveView_clicked(const QModelIndex &index)
    {
    int m_count=0;
    QStandardItemModel *model = new QStandardItemModel(0,0);
    QString sPath = m_SystemModel->fileInfo(index).absoluteFilePath();
    m_SystemListViewModel->setRootPath(sPath);
    ui->DriveListView->setRootIndex(m_SystemListViewModel->index(sPath));

    m_SystemModel->setRootPath(QDir::currentPath());
    m_SystemModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs );
    m_SystemListViewModel->setFilter( QDir::Files | QDir::NoDotAndDotDot );
     
    QStringList m_list;
    QDirIterator dirIt(sPath,QDirIterator::Subdirectories);
     
    while (dirIt.hasNext())
    {
    dirIt.next();
    if (QFileInfo(dirIt.filePath()).isFile())
    {
    if (QFileInfo(dirIt.filePath()).suffix() == "mp3" || QFileInfo(dirIt.filePath()).suffix() == ".avi")
    {
    m_list << dirIt.filePath();
     
    QModelIndex index = model->index(m_count, 0, QModelIndex());
    model->setHeaderData( 0, Qt::Horizontal, "File Name" );
    model->setHeaderData( 1, Qt::Horizontal, "Size" );
    model->setHeaderData( 2, Qt::Horizontal, "Type" );
    model->setHeaderData( 3, Qt::Horizontal, "Date Modified" );
     
    model->setData( index, dirIt.fileName(), Qt::DecorationRole );
    QStandardItem *item = new QStandardItem(dirIt.fileName());
    model->setItem(m_count, item);
     
    ui->DriveListView->setModel(model);
    m_count++;
    }
    }
    m_SystemListViewModel->setNameFilterDisables(false);
    }
    }@
    

    Even though I have used setHeaderData for Size, Type and Date Modified.... it doesnt get displayed. I am using QTreeView, as of now my code displays all the .mp3 files under Name category. I want to display the Size, Date Modified, Type etc details too.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.