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. IsIndexHidden of TableView never called

IsIndexHidden of TableView never called

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k 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
    stereomatching
    wrote on last edited by
    #1

    I am trying to create a tableView which only show directory, do anybody know how to do it?
    here is my code sofar

    @
    class customTableView : public QTableView
    {

    public:
    customTableView(QObject *parent = 0) : QTableView(0) {}

    protected:
    bool isIndexHidden( const QModelIndex &index ) const
    {
    QDirModel dirModel = static_cast<QDirModel>(model());
    qDebug() << dirModel->fileName(index);
    if(dirModel->fileInfo(index).isFile())
    return true;

        return false;
    }
    

    };

    class customViewTest : public QWidget
    {

    Q_OBJECT

    public:
    customViewTest() : QWidget(0)
    {
    model = new QDirModel(this);

        view = new QTreeView(this);
        view->setModel(model);
        connect(view, SIGNAL(clicked(QModelIndex)), this, SLOT(onTreeClick(QModelIndex)));
    
        customView = new customTableView(this);
        customView->setModel(model);
    
        QHBoxLayout *layout = new QHBoxLayout(this);
        layout->addWidget(view);
        layout->addWidget(customView);
    
        setLayout(layout);
    }
    

    private slots:
    void onTreeClick(QModelIndex const &index)
    {
    customView->setRootIndex(index);
    }

    private:
    QDirModel *model;
    QTreeView *view;
    customTableView *customView;
    };

    inline int customTableViewTest(QApplication &app)
    {
    customViewTest test;
    test.show();

    return app.exec();
    

    }
    @

    The method "isIndexHidden" never called when I press on the treeView
    Thanks a lot

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      bq. The method “isIndexHidden” never called when I press on the treeView

      But you implemented the method in customTableView.

      anyhow as from your previous post "here":http://qt-project.org/forums/viewthread/19510/ It seems like you want to filter the "files" from being displayed in the treeView.

      From "QDirModel documentation":http://qt-project.org/doc/qt-4.8/QDirModel.html#details

      bq. The usage of QDirModel is not recommended anymore. The QFileSystemModel class is a more performant alternative

      So you can use QFileSystemModel as well.
      and try the following code

      @treeModel = new QFileSystemModel;
      treeModel->setRootPath(QDir::root().path());
      treeModel->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot);
      ui->treeView->setModel(treeModel);@

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stereomatching
        wrote on last edited by
        #3

        I used that method before, it works perfectly
        But my purpose is show the data of the same model
        one by treeView, one by tableView

        bq. So you can use QFileSystemModel as well.

        I would like to if I can
        from my previous post "http://qt-project.org/forums/viewthread/19168/":
        The QFileSystemModel will crash when I rename a lot of files with multithread(QDirModel would not)
        if I rename those files in main thread the GUI will freeze

        Thanks

        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