C++ (Qt)class QDirModelExt : public QDirModel { Q_OBJECT public: typedef QDirModel parent; virtual Qt::ItemFlags flags( const QModelIndex &index ) const; virtual QVariant data( const QModelIndex &index, int role )const; virtual bool setData( const QModelIndex &index, const QVariant& value, int role ); private: mutable std::map<qint64, Qt::CheckState> m_checkedItems; }; Qt::ItemFlags QDirModelExt::flags( const QModelIndex & index ) const { return QDirModel::flags( index ) | Qt::ItemIsUserCheckable; } QVariant QDirModelExt::data( const QModelIndex& index, int role ) const { if( role == Qt::CheckStateRole && index.column()==0 ) { return QVariant( m_checkedItems[ index.internalId() ] ); } return parent::data( index, role );} bool QDirModelExt::setData( const QModelIndex& index, const QVariant& value, int role ) { if( role == Qt::CheckStateRole && index.column() == 0 ) { m_checkedItems[ index.internalId() ] = static_cast<Qt::CheckState>( value.toInt() ); return true; } return parent::setData(index, value, role); } использование: QSplitter *splitter = new QSplitter; QFileSystemModel *model = new QFileSystemModel; model->setRootPath( QDir::currentPath() ); QDirModelExt *dirModelExt = new QDirModelExt(); QTreeView *tree = new QTreeView( splitter ); tree->setModel( dirModelExt ); layout->addWidget( tree, .... );
setColumnHidden ( int column, bool hide )
... tree->setModel( dirModelExt ); tree->setColumnHidden(1,true); //размер tree->setColumnHidden(2,true); //тип tree->setColumnHidden(3,true); //дата изменения...
QFileSystemModel *model = new QFileSystemModel;model->setRootPath(QDir::currentPath());QTreeView *tree = new QTreeView(splitter);tree->setModel(model);