I want to add a custom column to the (table view) of the QFileDialog. Therefore I use the method "setProxyModel" of the class QFileDialog.

Code:
Qt Code:
  1. class QFileDialogProxyModel : public QSortFilterProxyModel{
  2. public:
  3. virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  4. Qt::ItemFlags flags(const QModelIndex &index) const;
  5. virtual int columnCount ( const QModelIndex & parent = QModelIndex() );
  6. virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
  7. };
  8.  
  9. QVariant QFileDialogProxyModel::data(const QModelIndex &index, int role/* = Qt::DisplayRole*/) const {
  10. if (!index.isValid())
  11. return QVariant();
  12. if (role == Qt::DisplayRole && index.column() == 4)
  13. return QString::number(rand() % 10); // add custom column! at the moment a random number
  14. return QSortFilterProxyModel::data(index, role);
  15. }
  16.  
  17. Qt::ItemFlags QFileDialogProxyModel::flags(const QModelIndex &index) const {
  18. if (!index.isValid())
  19. return 0;
  20. if (index.column() == 4)
  21. return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
  22. return QSortFilterProxyModel::flags(index);
  23. }
  24.  
  25. QVariant QFileDialogProxyModel::headerData ( int section, Qt::Orientation orientation, int role/* = Qt::DisplayRole */) const{
  26. if (section == 4 && orientation == Qt::Horizontal && role == Qt::DisplayRole)
  27. return tr("Notifications");
  28. return QSortFilterProxyModel::headerData(section, orientation, role);
  29. }
  30.  
  31. int QFileDialogProxyModel::columnCount ( const QModelIndex & parent/* = QModelIndex() */){
  32. return (parent.column() > 0) ? 0 : 5; //
  33. }
  34.  
  35. int main(int argc, char *argv[]){
  36. QApplication app(argc, argv);
  37. QFileDialog customDialog;
  38. customDialog.setProxyModel(new QFileDialogProxyModel());
  39. customDialog.exec();
  40. return 0;
  41. }
To copy to clipboard, switch view to plain text mode 

Result:
Just the filenames/order ("name"), size, type and data modified are displayed.
Desired is a additional column with the header name "Notifications". The contents should be contain random numbers.
Hopefully anybody can help me.