title: QFilesystemModel to display files only
body: <p>I have a requirement to display file selection dialogue. I can't use <code>QFileDialog</code> as we need to restrict the user access to the file system. I created a subclass of <code>QDialog</code> which has 2 <code>QTreeView</code>s; first one for displaying directories only and the second one for displaying files only. I have 2 <code>QFileSystemModel</code>s to serve content to these views, of which directory listing model is working as expected, but not file list model. File list model/view is not always showing the files, sometimes even showing files from parent directory and previous directory.</p>
  
  <p>How to display only files from the directory selected in the first (directory tree) view?</p>
  
  <p>Following is the code snippet I tried.</p>
  
  <pre><code>FileDialogue1::FileDialogue1(const QStringList&amp; locs, QWidget* prnt)
      : QDialog(prnt)
  {
      QHBoxLayout* hlayout = new QHBoxLayout(this);
      m_splitter = new QSplitter(this);
      m_dir_view = new QTreeView(m_splitter);
      m_dir_model = new QFileSystemModel(m_dir_view);
      m_dir_model-&gt;setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
      m_dir_view-&gt;setModel(m_dir_model);
      connect(m_dir_view, SIGNAL(clicked(QModelIndex)), SLOT(loadFileList(QModelIndex)));
      m_file_view = new QTreeView(m_splitter);
      m_file_model = new FileSystemModel(m_file_view);
      m_file_model-&gt;setFilter(QDir::NoDotAndDotDot | QDir::Files);
      m_file_view-&gt;setModel(m_file_model);
  
      // restrict user selection
      QGroupBox* locs_gb = new QGroupBox(tr("Available locations"), this);
      QVBoxLayout* vlayout = new QVBoxLayout(locs_gb);
      QSignalMapper* mapper = new QSignalMapper(locs_gb);
      connect(mapper, SIGNAL(mapped(QString)), SLOT(changeLocation(QString)));
      foreach (const QString&amp; loc, locs)
      {
          QRadioButton* radio = new QRadioButton(loc, locs_gb);
          vlayout-&gt;addWidget(radio, 0, Qt::AlignTop | Qt::AlignLeft);
          connect(radio, SIGNAL(clicked()), mapper, SLOT(map()));
          mapper-&gt;setMapping(radio, loc);
      }
      vlayout-&gt;addStretch(1);
  
      hlayout-&gt;addWidget(locs_gb, 0, Qt::AlignLeft);
      hlayout-&gt;addWidget(m_splitter);
  
      setMinimumSize(MIN_SIZE);
  }
  
  
  void FileDialogue1::changeLocation(const QString&amp; path)
  {        
      m_dir_view-&gt;setRootIndex(m_dir_model-&gt;setRootPath(path));
  }    
  
  void FileDialogue1::loadFileList(const QModelIndex&amp; idx)
  {        
      const QString path(m_dir_model-&gt;fileInfo(idx).absolutePath());
      m_file_view-&gt;setRootIndex(m_file_model-&gt;setRootPath(path));        
  }
  </code></pre>
  
  <p>Thanks in advance.</p>