Sort in column added to qtreeview
-
I have inherited QFileSystemModel like this.
It seems to work, kinda. But I have problem sorting.//fileinfobaseclass.h class FileBaseClass : public QFileSystemModel{ public: FileBaseClass(); FileBaseClass(QObject * parent); ~FileBaseClass(); int columnCount(const QModelIndex& parent = QModelIndex()) const; QVariant data(const QModelIndex& index,int role) const; };
.
//fileinfobaseclass.cpp QVariant FileBaseClass::data(const QModelIndex& index,int role) const{ if(!index.isValid()){ return QFileSystemModel::data(index,role);} if(index.column()==columnCount()-1){ QFileInfo *qf=new QFileInfo(QFileSystemModel::fileInfo(index).absoluteFilePath()); QString fileInfo; switch(role) { case(Qt::DisplayRole): { if ( qf->isWritable ()){ fileInfo+="rw"; } if ( qf->isSymLink ()){ fileInfo+="s"; } return fileInfo; } default:{} } } return QFileSystemModel::data(index,role); }
.
//In MainWindow
treeViewModel->sort ( 4 , Qt::AscendingOrder );