Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sort in column added to qtreeview
Forum Updated to NodeBB v4.3 + New Features

Sort in column added to qtreeview

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 510 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SwePtr
    wrote on last edited by SwePtr
    #1

    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 );

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved