If you don't have to use QFileSystemModel and you can live with QDirModel, then following code should solve your problem:
void MainWindow::OnTreeClicked( const QModelIndex& idx )
{
QFileInfo kFolderinfo
= m_pTreeModel
->filePath
( idx
);
m_pListModel->refresh(m_pListModel->index(kFolderinfo.filePath()));
ui->listView->setRootIndex( m_pListModel->index(kFolderinfo.filePath() ) );
}
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow),
m_pListModel( NULL ),
m_pTreeModel( NULL )
{
ui->setupUi(this);
ui->listView->setModel( m_pListModel );
m_pListModel
->setFilter
( QDir::NoDotAndDotDot |
QDir::Files );
ui->listView->setRootIndex( m_pListModel->index(strDesktop) );
ui->treeView->setModel( m_pTreeModel );
m_pTreeModel
->setFilter
( QDir::NoDotAndDotDot |
QDir::AllDirs );
ui->treeView->setRootIsDecorated( false );
ui->treeView->setRootIndex( m_pTreeModel->index(strDesktop) );
connect( ui->treeView, SIGNAL( clicked( const QModelIndex& ) ), this, SLOT( OnTreeClicked( const QModelIndex& ) ) );
}
void MainWindow::OnTreeClicked( const QModelIndex& idx )
{
QFileInfo kFolderinfo = m_pTreeModel->filePath( idx );
m_pListModel->refresh(m_pListModel->index(kFolderinfo.filePath()));
ui->listView->setRootIndex( m_pListModel->index(kFolderinfo.filePath() ) );
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_pListModel( NULL ),
m_pTreeModel( NULL )
{
m_pListModel = new QDirModel();
m_pTreeModel = new QDirModel();
QString strDesktop = QDesktopServices::storageLocation( QDesktopServices::DesktopLocation );
ui->setupUi(this);
ui->listView->setModel( m_pListModel );
m_pListModel->setFilter( QDir::NoDotAndDotDot | QDir::Files );
ui->listView->setRootIndex( m_pListModel->index(strDesktop) );
ui->treeView->setModel( m_pTreeModel );
m_pTreeModel->setFilter( QDir::NoDotAndDotDot | QDir::AllDirs );
ui->treeView->setRootIsDecorated( false );
ui->treeView->setRootIndex( m_pTreeModel->index(strDesktop) );
connect( ui->treeView, SIGNAL( clicked( const QModelIndex& ) ), this, SLOT( OnTreeClicked( const QModelIndex& ) ) );
}
To copy to clipboard, switch view to plain text mode
Bookmarks