I am trying to customize QFileDialog, so that custom information is dispayed in 'Type' column for certain files and directories. I've started by subclassing QFileSystemModel and redefining type() function. So, for certain file extensions it would return custom type. Now I want to use this class as model for QFileDialog and I see only one possibility. Namely, use proxy model. So, I have my custom file dialog class, which is derived from QFileDialog that has this in a constructor:

Qt Code:
  1. MyFileDialog::MyFileDialog
  2. (
  3. const QList<QUrl> &a_urls,
  4. QWidget *parent,
  5. const QString &caption,
  6. const QString &directory,
  7. const QString &filter
  8. )
  9. : QFileDialog(parent,caption,directory,filter)
  10. {
  11. setSidebarUrls(a_urls);
  12. QListView *sidebar = this->findChild<QListView *>("sidebar");
  13. m_proxy = new QSortFilterProxyModel();
  14. QFileDialog::setProxyModel(m_proxy);
  15. m_data = new MyFileSystemModel();
  16. QString rootPath = this->directory().path();
  17. m_data->setRootPath(rootPath);
  18. m_proxy->setSourceModel(m_data);
To copy to clipboard, switch view to plain text mode 

Now I am getting memory access error when file dialog appears and I try to select anything there.

I also see another problem here. If I comment out last line (m_proxy->setSourceModel(m_data)) everything works except for sidebar. I suspect there may be a bug in Qt's qfiledialog.cpp setProxyModel() function. While proxyModel is set as model for list and tree views

Qt Code:
  1. if (proxyModel != 0) {
  2. proxyModel->setParent(this);
  3. d->proxyModel = proxyModel;
  4. proxyModel->setSourceModel(d->model);
  5. d->qFileDialogUi->listView->setModel(d->proxyModel);
  6. d->qFileDialogUi->treeView->setModel(d->proxyModel);
  7. connect(d->proxyModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
  8. this, SLOT(_q_rowsInserted(const QModelIndex &)));
To copy to clipboard, switch view to plain text mode 

it is not done for sidebar.

So, I have two questions here: 1) what am I doing wrong here or is this a bug in Qt? and 2) is there a better way to get custom file dialog working besides rewriting it from scratch?

Any advise would be greatly appreciated. Thanks.