Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Display Audio File Attributes in QTreeView
Forum Updated to NodeBB v4.3 + New Features

Display Audio File Attributes in QTreeView

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 904 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stoned Jesus
    wrote on last edited by
    #1

    Well I need to display details of all .mp3 files present in my system drives. I am using QTreeView which gives me File Name, Size, Type and Date Modified by default to display. Here is the sample code:
    @void DetailView::on_DriveView_clicked(const QModelIndex &index)
    {
    int m_count=0;
    QStringList m_list;
    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 );

    QDirIterator dirIt(sPath,QDirIterator::Subdirectories);

    while (dirIt.hasNext())
    {
    dirIt.next();
    if (QFileInfo(dirIt.filePath()).isFile())
    {
    if (QFileInfo(dirIt.filePath()).suffix() == "mp3")
    {
    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);
    

    }
    }@

    When I run the app, Have a look at my code, even though I have used setHeaderData for Size, Type and Date Modified, it gets displayed when I run the application but the moment i click any system drive, only File Name appears and rest doesn't 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.

    --
    Thanks & Regards,
    Stoned Jesus

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved