Results 1 to 5 of 5

Thread: how to use QSortFilterProxyModel with QtreeWidget?

  1. #1
    Join Date
    Jan 2006
    Posts
    46
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default how to use QSortFilterProxyModel with QtreeWidget?

    I use QtreeWidget to load an xml xbel file using the sax example given with Qt4.
    I would like to put a lineEdit and use it to filter my QtreeWidget like konqueror bookmark editor does (or amarok etc...).

    Here is the code I use, following the documentation exemple:
    Qt Code:
    1. QAbstractItemModel * sourceModel;
    2. sourceModel = ui.treeWidget->model();
    3.  
    4. proxyModel->setSourceModel(sourceModel);
    5. ui.treeWidget->setModel(proxyModel);
    6.  
    7. proxyModel->setFilterRegExp(QRegExp(".png", Qt::CaseInsensitive,
    8. QRegExp::FixedString));
    To copy to clipboard, switch view to plain text mode 

    The problem is that setModel doesn´t work that way with QtreeWidget, it seems to be private or something, here is the error I get on compile:
    Qt Code:
    1. /usr/local/Trolltech/Qt-4.2.0-tp1/include/QtGui/qtreewidget.h:301: error: "virtual void QTreeWidget::setModel(QAbstractItemModel*)" is private
    2. myapp.cpp:108: error: within this context
    3. make: *** [myapp.o] Error 1
    To copy to clipboard, switch view to plain text mode 

    any idea how to do it right?

    I have another question, the doc says about QSortFilterProxyModel
    For hierarchical models, the filter is applied recursively to all children. If a parent item doesn't match the filter, none of its children will be shown
    . I would like all parent items to be shown as long as one of their children match the filter. How could I do that?

    Thanx in advance

    Pat

  2. #2
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to use QSortFilterProxyModel with QtreeWidget?

    I believe that in order to be able to call setModel you will need to use a QTableView rather than a QTableWidget.

  3. #3
    Join Date
    Jan 2006
    Posts
    46
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to use QSortFilterProxyModel with QtreeWidget?

    that´s ok thanx I found out. I had to use:

    Qt Code:
    1. ui.treeWidget->QtreeWidget::setModel(proxyModel);
    To copy to clipboard, switch view to plain text mode 

    instead of

    Qt Code:
    1. ui.treeWidget->setModel(proxyModel);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to use QSortFilterProxyModel with QtreeWidget?

    QTreeWidget has it's own strictly private model and it is not meant to be changed by hacking like you do (assuming that is QTreeView::setModel() you are calling). I doubt it would work very well.. QTreeWidget implementation for example does some casting which assumes that model indexes' internal pointers point to a QTreeWidgetItem. This is not true in your case when you have changed the underlying model. The methods like QTreeWidget::model() and QTreeWidget::setModel() have not been declared as private with no reason.

    Use a QTreeView if you want to use a model rather than the item approach QTreeWidget offers!
    J-P Nurmi

  5. #5
    Join Date
    Feb 2011
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: how to use QSortFilterProxyModel with QtreeWidget?

    Quote Originally Posted by jpn View Post
    QTreeWidget has it's own strictly private model and it is not meant to be changed by hacking like you do (assuming that is QTreeView::setModel() you are calling). I doubt it would work very well.. QTreeWidget implementation for example does some casting which assumes that model indexes' internal pointers point to a QTreeWidgetItem. This is not true in your case when you have changed the underlying model. The methods like QTreeWidget::model() and QTreeWidget::setModel() have not been declared as private with no reason.

    Use a QTreeView if you want to use a model rather than the item approach QTreeWidget offers!
    And if i want to change the display text of the my files in QTreeView? Do you know how can i do? This is my big problem, right now...

    With QTreeView i can to change the model to QFileSystemModel and in QTreeWidget i can't. But in QTreeWidget i can to change the text files display and in QTreeView i can't. And i need both, to change text files display and to use QFileSystemModel. =/

    If can you help me...

Similar Threads

  1. Two-row header for QTreeWidget
    By wetzel in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2006, 12:26
  2. How to capture resizing of QTreeWidget columns?
    By simk in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2006, 06:10
  3. QTreeWidget problem!!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 10th March 2006, 11:47
  4. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07:32
  5. [QT4] Selected row in a QTreeWidget
    By vfernandez in forum Qt Programming
    Replies: 3
    Last Post: 9th March 2006, 11:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.