The Ultimate Qt Community site
Home News Forum Wiki Contest FAQ Links

Go Back   Qt Centre Forum > Qt > Newbie

Newbie Newbie to Qt? Ask your questions here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 14th August 2008, 17:30
killerwookie99 killerwookie99 is offline
Novice
 
Join Date: Aug 2008
Qt products used: Qt4
Qt platforms used: Unix/X11
Posts: 33
Thanks: 12
Thanked 0 Times in 0 Posts
Question QDirModel shared in two TreeViews with different TreeView configurations...

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?

Reply With Quote
  #2  
Old 14th August 2008, 18:15
wysota wysota is offline
Guru
 
Join Date: Jan 2006
Location: Warsaw, Poland
Qt products used: Qt3, Qt4
Qt platforms used: Unix/X11, Windows
Posts: 11,663
Thanks: 3
Thanked 1,640 Times in 1,591 Posts
Default Re: QDirModel shared in two TreeViews with different TreeView configurations...

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

Reply With Quote
The following user says thank you to wysota for this useful post:
killerwookie99 (15th August 2008)
  #3  
Old 15th August 2008, 00:56
killerwookie99 killerwookie99 is offline
Novice
 
Join Date: Aug 2008
Qt products used: Qt4
Qt platforms used: Unix/X11
Posts: 33
Thanks: 12
Thanked 0 Times in 0 Posts
Default Re: QDirModel shared in two TreeViews with different TreeView configurations...

What about QProxyModel? It says not to use it, is there something better?

Last edited by killerwookie99; 15th August 2008 at 01:31.
Reply With Quote
  #4  
Old 15th August 2008, 06:33
wysota wysota is offline
Guru
 
Join Date: Jan 2006
Location: Warsaw, Poland
Qt products used: Qt3, Qt4
Qt platforms used: Unix/X11, Windows
Posts: 11,663
Thanks: 3
Thanked 1,640 Times in 1,591 Posts
Default Re: QDirModel shared in two TreeViews with different TreeView configurations...

Yes, you have a link to the docs in my previous post.

Reply With Quote
The following user says thank you to wysota for this useful post:
killerwookie99 (15th August 2008)
  #5  
Old 15th August 2008, 17:51
killerwookie99 killerwookie99 is offline
Novice
 
Join Date: Aug 2008
Qt products used: Qt4
Qt platforms used: Unix/X11
Posts: 33
Thanks: 12
Thanked 0 Times in 0 Posts
Default Re: QDirModel shared in two TreeViews with different TreeView configurations...

Alright I'll stick with it, its use is just a little confusing for me.

Last edited by killerwookie99; 15th August 2008 at 18:01.
Reply With Quote
  #6  
Old 17th August 2008, 19:23
wysota wysota is offline
Guru
 
Join Date: Jan 2006
Location: Warsaw, Poland
Qt products used: Qt3, Qt4
Qt platforms used: Unix/X11, Windows
Posts: 11,663
Thanks: 3
Thanked 1,640 Times in 1,591 Posts
Default Re: QDirModel shared in two TreeViews with different TreeView configurations...

What is confusing? The difference between QProxyModeland QAbstractProxyModel which is the base of QSortFilterProxyModel?

Reply With Quote
  #7  
Old 18th August 2008, 02:46
killerwookie99 killerwookie99 is offline
Novice
 
Join Date: Aug 2008
Qt products used: Qt4
Qt platforms used: Unix/X11
Posts: 33
Thanks: 12
Thanked 0 Times in 0 Posts
Default Re: QDirModel shared in two TreeViews with different TreeView configurations...

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
Qt Code:
  1. #include <QtGui/QSortFilterProxyModel>
  2.  
  3. class MySortFilterProxyModel : public QSortFilterProxyModel
  4. {
  5.   Q_OBJECT
  6. public:
  7.   MySortFilterProxyModel(QObject *parent = 0);
  8.  
  9. protected:
  10.   bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
  11. };
MySortFilterProxyModel.cpp
Qt Code:
  1. #include "MySortFilterProxyModel.h"
  2.  
  3. #include <iostream>
  4.  
  5. MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
  6. {
  7.  
  8. }
  9.  
  10. bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
  11. {
  12.   QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
  13.  
  14. std::cout << "Index: " << sourceModel()->data(index0).toString().toStdString() << std::endl;
  15.  
  16.   return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
  17. }
MainWindow.cpp
...
Qt Code:
  1. QDirModel *dirModel = new QDirModel();
  2. MySortFilterProxyModel *proxyModel = new MySortFilterProxyModel();
  3.  
  4. proxyModel->setSourceModel(dirModel); // SEGFAULTS
  5.  
...

Any ideas?

Reply With Quote
  #8  
Old 18th August 2008, 08:23
wysota wysota is offline
Guru
 
Join Date: Jan 2006
Location: Warsaw, Poland
Qt products used: Qt3, Qt4
Qt platforms used: Unix/X11, Windows
Posts: 11,663
Thanks: 3
Thanked 1,640 Times in 1,591 Posts
Default Re: QDirModel shared in two TreeViews with different TreeView configurations...

What is the source model? Is it a custom model or a predefined one?

Reply With Quote
  #9  
Old 18th August 2008, 17:39
killerwookie99 killerwookie99 is offline
Novice
 
Join Date: Aug 2008
Qt products used: Qt4
Qt platforms used: Unix/X11
Posts: 33
Thanks: 12
Thanked 0 Times in 0 Posts
Default Re: QDirModel shared in two TreeViews with different TreeView configurations...

It's using the regular qdirmodel from qt...

Reply With Quote
  #10  
Old 18th August 2008, 20:22
wysota wysota is offline
Guru
 
Join Date: Jan 2006
Location: Warsaw, Poland
Qt products used: Qt3, Qt4
Qt platforms used: Unix/X11, Windows
Posts: 11,663
Thanks: 3
Thanked 1,640 Times in 1,591 Posts
Default Re: QDirModel shared in two TreeViews with different TreeView configurations...

Could you print the backtrace from the debugger upon the segfault?

Reply With Quote
  #11  
Old 29th August 2008, 17:44
killerwookie99 killerwookie99 is offline
Novice
 
Join Date: Aug 2008
Qt products used: Qt4
Qt platforms used: Unix/X11
Posts: 33
Thanks: 12
Thanked 0 Times in 0 Posts
Default Re: QDirModel shared in two TreeViews with different TreeView configurations...

You want a truss or something different, sorry my debugger knowledge is limited...

Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes