[Qt-interest] QTreeView, proxy model and expandable state
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Mon Apr 13 19:20:53 CEST 2009
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Dmitry Baryshev
> Sent: Monday, April 13, 2009 10:13 AM
> To: qtInterest
> Subject: Re: [Qt-interest] QTreeView, proxy model and expandable state
>
> 2009/4/13 Dmitry Baryshev <ksquirrel.iv at gmail.com>:
> > 2009/4/13 Scott Aron Bloom <Scott.Bloom at sabgroup.com>:
> >> It will really depend on what you implemented in your filterAcceptsRows
> >> method.
> >>
> >> Without seeing the guts of it, I have no idea how to help you.
> >>
> >> Scott
> >>
> >> -----Original Message-----
> >> From: qt-interest-bounces at trolltech.com
> >> [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Dmitry Baryshev
> >> Sent: Monday, April 13, 2009 8:26 AM
> >> To: qt-interest at trolltech.com
> >> Subject: [Qt-interest] QTreeView, proxy model and expandable state
> >>
> >> Hi.
> >>
> >> I use QTreeView+QFileSystemModel. It seems to work fine, all directory
> >> items have expanable flag ("+" on the left side). Now I've added
> >> QSortFilterProxyModel with only one reimplemented method - "bool
> >> SortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex
> >> &parent) const". Now all directory items in QTreeView lost its
> >> expandable state - no '+' elements.
> >> QTreeView::setItemsExpandable(true) doesn't help. I don't understand
> >> the logic why filtering affects expandable states? Could you please
> >> help me with this strange problem? Thanks!
> >>
> >> --
> >> _______________________________________________
> >> Qt-interest mailing list
> >> Qt-interest at trolltech.com
> >> http://lists.trolltech.com/mailman/listinfo/qt-interest
> >>
> >> _______________________________________________
> >> Qt-interest mailing list
> >> Qt-interest at trolltech.com
> >> http://lists.trolltech.com/mailman/listinfo/qt-interest
> >>
> >
> > In any case it doesn't work. For example:
> >
> > bool MySortFilterProxyModel::filterAcceptsRow(int row, const
> > QModelIndex &parent) const
> > {
> > return true;
> > }
> >
> > --
> >
>
> Full source code to reproduce:
>
> .h
> --
>
> #ifndef FLL_H
> #define FLL_H
>
> #include <QTreeView>
>
> class fl : public QTreeView
> {
> Q_OBJECT
>
> public:
> fl(QWidget *parent = 0);
> };
>
> #endif
>
> .cpp
> ----
>
> #include <QFileSystemModel>
> #include <QSortFilterProxyModel>
>
> #include "fl.h"
>
> class SortFilterProxyModel : public QSortFilterProxyModel
> {
> public:
> SortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
> {
> setFilterRegExp(".*");
> }
>
> protected:
> bool filterAcceptsRow(int /* row */, const QModelIndex &/*
> parent */) const
> {
> return true;
> }
> };
>
> #define USE_PROXY_MODEL
>
> fl::fl(QWidget *parent) : QTreeView(parent)
> {
> QFileSystemModel *model;
>
> model = new QFileSystemModel;
> model->setResolveSymlinks(true);
> model->setNameFilterDisables(false);
> model->setReadOnly(true);
>
> SortFilterProxyModel *proxyModel;
>
> proxyModel = new SortFilterProxyModel(this);
> proxyModel->setSourceModel(model);
> proxyModel->setDynamicSortFilter(true);
>
> #ifdef USE_PROXY_MODEL
> QModelIndex root =
> proxyModel->mapFromSource(model->setRootPath(QDir::rootPath()));
> setModel(proxyModel);
> #else
> QModelIndex root = model->setRootPath(QDir::rootPath());
> setModel(model);
> #endif
>
> setRootIndex(root);
> }
>
> /*********************************/
>
> define or undef USE_PROXY_MODEL to test two cases with and without proxy
> model.
>
> Result:
>
> 1) without proxy model: http://img258.imageshack.us/img258/7271/fl1.png
> 2) with proxy model: http://img258.imageshack.us/img258/1606/fl2.png
>
> The system is Debian Lenny with Qt 4.4.3.
>
> Maybe it is a bug?
>
> --
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
Its probably your setFilterRegExp call... Try turning that off, and leaving the filterAcceptsRow... See what happens
Scott
More information about the Qt-interest-old
mailing list