IsIndexHidden of TableView never called
-
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 -
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);@ -
I used that method before, it works perfectly
But my purpose is show the data of the same model
one by treeView, one by tableViewbq. 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 freezeThanks