rendered paste body#include <QtCore>#include <QtGui>class CheckboxProxyModel : public QSortFilterProxyModel{public: CheckboxProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {} QVariant data(const QModelIndex &index, int role) const { if (index.column() < 3) { if (role == Qt::DisplayRole) return QString("Checkbox %1").arg(index.column()+1); else return QVariant(); } else return QSortFilterProxyModel::data(index, role); } QVariant headerData(int section, Qt::Orientation orientation, int role) const { if (section < 3) { if (role == Qt::DisplayRole) return QString("Hallo Welt!"); else return QVariant(); } else // headerData uses mapToSource with section as the row parameter // so I don't need to decrement section by three return QSortFilterProxyModel::headerData(section, orientation, role); } QModelIndex mapToSource(const QModelIndex &proxyIndex) const { if (proxyIndex.column() < 3) return QModelIndex(); else { QModelIndex tmp = QSortFilterProxyModel::index(proxyIndex.row(), proxyIndex.column()-3, proxyIndex.parent()); return QSortFilterProxyModel::mapToSource(tmp); } } QModelIndex mapFromSource(const QModelIndex &sourceIndex) const { return QSortFilterProxyModel::index(sourceIndex.row(), sourceIndex.column()+3, sourceIndex.parent()); } int columnCount(const QModelIndex &parent) const { return QSortFilterProxyModel::columnCount(parent)+3; }};int main(int argc, char *argv[]){ QApplication a(argc, argv); // Create view and model QTreeView *view = new QTreeView(); QFileSystemModel *model = new QFileSystemModel(view); // Get a root path for the model QString rootPath = QFileDialog::getExistingDirectory(view, "Choose directory"); if (rootPath.isEmpty()) { QMessageBox::critical(view, "Error!", "You did not choose a directory!"); return -1; } QModelIndex rootModelIndex = model->setRootPath(rootPath); // Create proxy model CheckboxProxyModel *proxyModel = new CheckboxProxyModel(view); proxyModel->setSourceModel(model); view->setModel(proxyModel); // Set the root index of the view to the root path of the model view->setRootIndex(proxyModel->mapFromSource(rootModelIndex)); view->show(); return a.exec();}