View Full Version : QDirModel shared in two TreeViews with different TreeView configurations...
killerwookie99
14th August 2008, 16:30
I've been looking at examples and reading docs etc. I'd like run my thoughts by someone on how this would work, because I haven't run across this scenario anywhere.
Problem:
I would like to use a custom QDirModel for two TreeViews in one splitter pane, but I'd like to customize the look of one vs the other. currently doing via two QDirModels...:(
So on the left side I would like just folders and the name column (in TreeView form)
On the right I'd like the full up TreeView.
So would I implement this by using a QAbstractItemModel? If, yes how would this be accomplished? If no how can I use one custom QDirModel in two TreeViews with different layouts? What are your thoughts?
wysota
14th August 2008, 17:15
Hide all the columns but the first one in the tree. If you want to filter out files, use QSortFilterProxyModel and in its filterAcceptsRow() check if the index is a file or a directory and return false or true respectively. Then you'll be able to use one model for both views (one of them will additionaly be using a proxy model).
killerwookie99
14th August 2008, 23:56
What about QProxyModel? It says not to use it, is there something better?
wysota
15th August 2008, 05:33
Yes, you have a link to the docs in my previous post.
killerwookie99
15th August 2008, 16:51
Alright I'll stick with it, its use is just a little confusing for me.
wysota
17th August 2008, 18:23
What is confusing? The difference between QProxyModel and QAbstractProxyModel which is the base of QSortFilterProxyModel?
killerwookie99
18th August 2008, 01:46
When I try to do this it segfaults and I'm not sure if it's because I'm missing a function or what, but here's a simplistic version of what I tried to do...oh and it segfaults even when I comment out filterAcceptsRow...
MySortFilterProxyModel.h
#include <QtGui/QSortFilterProxyModel>
class MySortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
MySortFilterProxyModel(QObject *parent = 0);
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
};
MySortFilterProxyModel.cpp
#include "MySortFilterProxyModel.h"
#include <iostream>
MySortFilterProxyModel::MySortFilterProxyModel(QOb ject *parent) : QSortFilterProxyModel(parent)
{
}
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
std::cout << "Index: " << sourceModel()->data(index0).toString().toStdString() << std::endl;
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
MainWindow.cpp
...
QDirModel *dirModel = new QDirModel();
MySortFilterProxyModel *proxyModel = new MySortFilterProxyModel();
proxyModel->setSourceModel(dirModel); // SEGFAULTS
...
Any ideas?
wysota
18th August 2008, 07:23
What is the source model? Is it a custom model or a predefined one?
killerwookie99
18th August 2008, 16:39
It's using the regular qdirmodel from qt...
wysota
18th August 2008, 19:22
Could you print the backtrace from the debugger upon the segfault?
killerwookie99
29th August 2008, 16:44
You want a truss or something different, sorry my debugger knowledge is limited...
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.