1 Attachment(s)
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:
Code:
// Displays Files in Detail View on Clicking Drive
void DetailView
::on_DriveView_clicked(const QModelIndex &index
) {
int m_count=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()).
suffix() == "mp3" ||
QFileInfo(dirIt.
filePath()).
suffix() == ".avi") {
m_list << dirIt.filePath();
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 );
model->setItem(m_count, item);
ui->DriveListView->setModel(model);
m_count++;
}
}
m_SystemListViewModel->setNameFilterDisables(false);
}
}
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:
Attachment 8452
How to achieve it?
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,
_
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:
Code:
void DetailView
::on_DriveView_clicked(const QModelIndex &index
) {
int m_count_row = 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()).
suffix() == "mp3" ||
(QFileInfo(dirIt.
filePath()).
suffix() == "mts" ) ||
(QFileInfo(dirIt.
filePath()).
suffix() == "m2ts" )) {
m_list << dirIt.filePath();
model->setHeaderData( 0, Qt::Horizontal, "Name" );
model->setHeaderData( 1, Qt::Horizontal, "Type" );
model->setHeaderData( 2, Qt::Horizontal, "Size" );
model->setHeaderData( 3, Qt::Horizontal, "Date Modified" );
model->setData( m_index, dirIt.fileName(), Qt::DecorationRole );
model->setItem(m_count_row, 0, itemName);
model->setData( m_index, dirIt.fileInfo().suffix(), Qt::DecorationRole );
model->setItem(m_count_row, 1, itemExtention);
model->setData( m_index, dirIt.fileInfo().size(), Qt::DecorationRole );
float fFileSize = dirIt.fileInfo().size();
float fFileKB = fFileSize / 1024; //kilobyte
float fFileMB = fFileKB / 1024; //megabyte
float fFinalSize = ceilf(fFileMB * 100) / 100;
model->setItem(m_count_row, 2, itemSize);
ui->DriveListView->setModel(model);
ui->DriveListView->setRootIsDecorated(false);
m_count_row++;
}
}
m_SystemListViewModel->setNameFilterDisables(false);
}
}
Quote:
Originally Posted by
anda_skoa
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,
_