public:
virtual QVariant headerData
( int section, Qt
::Orientation orientation,
int role
= Qt
::DisplayRole ) const;
};
QVariant QFileDialogProxyModel
::data(const QModelIndex &index,
int role
/* = Qt::DisplayRole*/) const { if (!index.isValid())
if (role == Qt::DisplayRole && index.column() == 4)
return QString::number(rand() % 10);
// add custom column! at the moment a random number }
Qt
::ItemFlags QFileDialogProxyModel
::flags(const QModelIndex &index
) const { if (!index.isValid())
return 0;
if (index.column() == 4)
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant QFileDialogProxyModel
::headerData ( int section, Qt
::Orientation orientation,
int role
/* = Qt::DisplayRole */) const{ if (section == 4 && orientation == Qt::Horizontal && role == Qt::DisplayRole)
return tr("Notifications");
}
int QFileDialogProxyModel
::columnCount ( const QModelIndex & parent
/* = QModelIndex() */){ return (parent.column() > 0) ? 0 : 5; //
}
int main(int argc, char *argv[]){
customDialog.setProxyModel(new QFileDialogProxyModel());
customDialog.exec();
return 0;
}
class QFileDialogProxyModel : public QSortFilterProxyModel{
public:
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
virtual int columnCount ( const QModelIndex & parent = QModelIndex() );
virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
};
QVariant QFileDialogProxyModel::data(const QModelIndex &index, int role/* = Qt::DisplayRole*/) const {
if (!index.isValid())
return QVariant();
if (role == Qt::DisplayRole && index.column() == 4)
return QString::number(rand() % 10); // add custom column! at the moment a random number
return QSortFilterProxyModel::data(index, role);
}
Qt::ItemFlags QFileDialogProxyModel::flags(const QModelIndex &index) const {
if (!index.isValid())
return 0;
if (index.column() == 4)
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
return QSortFilterProxyModel::flags(index);
}
QVariant QFileDialogProxyModel::headerData ( int section, Qt::Orientation orientation, int role/* = Qt::DisplayRole */) const{
if (section == 4 && orientation == Qt::Horizontal && role == Qt::DisplayRole)
return tr("Notifications");
return QSortFilterProxyModel::headerData(section, orientation, role);
}
int QFileDialogProxyModel::columnCount ( const QModelIndex & parent/* = QModelIndex() */){
return (parent.column() > 0) ? 0 : 5; //
}
int main(int argc, char *argv[]){
QApplication app(argc, argv);
QFileDialog customDialog;
customDialog.setProxyModel(new QFileDialogProxyModel());
customDialog.exec();
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks