Results 1 to 3 of 3

Thread: How to display Details of Audio File in QTreeView

  1. #1
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    4
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation 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:
    Qt Code:
    1. // Displays Files in Detail View on Clicking Drive
    2. void DetailView::on_DriveView_clicked(const QModelIndex &index)
    3. {
    4. int m_count=0;
    5. QString sPath = m_SystemModel->fileInfo(index).absoluteFilePath();
    6. m_SystemListViewModel->setRootPath(sPath);
    7. ui->DriveListView->setRootIndex(m_SystemListViewModel->index(sPath));
    8.  
    9. m_SystemModel->setRootPath(QDir::currentPath());
    10. m_SystemModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs );
    11. m_SystemListViewModel->setFilter( QDir::Files | QDir::NoDotAndDotDot );
    12.  
    13. QStringList m_list;
    14. QDirIterator dirIt(sPath,QDirIterator::Subdirectories);
    15.  
    16. while (dirIt.hasNext())
    17. {
    18. dirIt.next();
    19. if (QFileInfo(dirIt.filePath()).isFile())
    20. {
    21. if (QFileInfo(dirIt.filePath()).suffix() == "mp3" || QFileInfo(dirIt.filePath()).suffix() == ".avi")
    22. {
    23. m_list << dirIt.filePath();
    24.  
    25. QModelIndex index = model->index(m_count, 0, QModelIndex());
    26. model->setHeaderData( 0, Qt::Horizontal, "File Name" );
    27. model->setHeaderData( 1, Qt::Horizontal, "Size" );
    28. model->setHeaderData( 2, Qt::Horizontal, "Type" );
    29. model->setHeaderData( 3, Qt::Horizontal, "Date Modified" );
    30.  
    31. model->setData( index, dirIt.fileName(), Qt::DecorationRole );
    32. QStandardItem *item = new QStandardItem(dirIt.fileName());
    33. model->setItem(m_count, item);
    34.  
    35. ui->DriveListView->setModel(model);
    36. m_count++;
    37. }
    38. }
    39. m_SystemListViewModel->setNameFilterDisables(false);
    40. }
    41. }
    To copy to clipboard, switch view to plain text mode 
    Have a look at my code, even though I have used setHeaderData for Size, Type and Date Modified, it gets displayed when run the application but when i click any 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. Here is sample pic:
    File.JPG
    How to achieve it?
    Last edited by owais_blore; 22nd November 2012 at 13:28.

  2. The following user says thank you to owais_blore for this useful post:


  3. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to display Details of Audio File in QTreeView

    You only set data for the first column, if you want data in the other columns you have to add that data to the model.

    The view can only display data that the model provides. Your model only knows about the file name, it can't provide any other data yet.

    Cheers,
    _

  4. The following 2 users say thank you to anda_skoa for this useful post:

    owais_blore (26th November 2012)

  5. #3
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    4
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to display Details of Audio File in QTreeView

    Thanks buddy. As explained, I tried adding data to model and its working. Here is the code:
    Qt Code:
    1. void DetailView::on_DriveView_clicked(const QModelIndex &index)
    2. {
    3. int m_count_row = 0;
    4.  
    5. QString sPath = m_SystemModel->fileInfo(index).absoluteFilePath();
    6. m_SystemListViewModel->setRootPath(sPath);
    7. ui->DriveListView->setRootIndex(m_SystemListViewModel->index(sPath));
    8.  
    9. m_SystemModel->setRootPath(QDir::currentPath());
    10. m_SystemModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs );
    11. m_SystemListViewModel->setFilter( QDir::Files | QDir::NoDotAndDotDot );
    12.  
    13. QStringList m_list;
    14. QDirIterator dirIt(sPath,QDirIterator::Subdirectories);
    15.  
    16. while (dirIt.hasNext())
    17. {
    18. dirIt.next();
    19. if (QFileInfo(dirIt.filePath()).isFile())
    20. {
    21. if (QFileInfo(dirIt.filePath()).suffix() == "mp3" ||(QFileInfo(dirIt.filePath()).suffix() == "mts" ) ||(QFileInfo(dirIt.filePath()).suffix() == "m2ts" ))
    22. {
    23. m_list << dirIt.filePath();
    24.  
    25. QModelIndex m_index = model->index(m_count_row, 0, QModelIndex());
    26. model->setHeaderData( 0, Qt::Horizontal, "Name" );
    27. model->setHeaderData( 1, Qt::Horizontal, "Type" );
    28. model->setHeaderData( 2, Qt::Horizontal, "Size" );
    29. model->setHeaderData( 3, Qt::Horizontal, "Date Modified" );
    30.  
    31. model->setData( m_index, dirIt.fileName(), Qt::DecorationRole );
    32. QStandardItem *itemName = new QStandardItem(dirIt.fileName());
    33. model->setItem(m_count_row, 0, itemName);
    34.  
    35. model->setData( m_index, dirIt.fileInfo().suffix(), Qt::DecorationRole );
    36. QStandardItem *itemExtention = new QStandardItem( dirIt.fileInfo().suffix());
    37. model->setItem(m_count_row, 1, itemExtention);
    38.  
    39. model->setData( m_index, dirIt.fileInfo().size(), Qt::DecorationRole );
    40. float fFileSize = dirIt.fileInfo().size();
    41. float fFileKB = fFileSize / 1024; //kilobyte
    42. float fFileMB = fFileKB / 1024; //megabyte
    43. float fFinalSize = ceilf(fFileMB * 100) / 100;
    44.  
    45. QString sSizeValue = QString::number(fFinalSize);
    46. QStandardItem *itemSize = new QStandardItem(sSizeValue + " MB");
    47. model->setItem(m_count_row, 2, itemSize);
    48.  
    49. ui->DriveListView->setModel(model);
    50. ui->DriveListView->setRootIsDecorated(false);
    51. m_count_row++;
    52. }
    53. }
    54.  
    55. m_SystemListViewModel->setNameFilterDisables(false);
    56. }
    57. }
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by anda_skoa View Post
    You only set data for the first column, if you want data in the other columns you have to add that data to the model.

    The view can only display data that the model provides. Your model only knows about the file name, it can't provide any other data yet.

    Cheers,
    _

  6. The following user says thank you to owais_blore for this useful post:


Similar Threads

  1. Replies: 0
    Last Post: 20th November 2012, 11:05
  2. play audio file
    By hema in forum Qt Quick
    Replies: 1
    Last Post: 11th August 2011, 06:27
  3. Replies: 0
    Last Post: 1st July 2010, 05:21
  4. Replies: 1
    Last Post: 11th November 2009, 18:28
  5. Updating File attributes and it's summary details
    By senthilsp in forum Qt Programming
    Replies: 1
    Last Post: 11th November 2009, 14:31

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.