Results 1 to 11 of 11

Thread: How to refresh treeview when QFileSystemModel's filterList changed?

  1. #1
    Join Date
    Jul 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How to refresh treeview when QFileSystemModel's filterList changed?

    i used a lineEdit to get filename filter from user, so when the text changed, i update the Namefilter of QFileSystemModel, but i must collpse current dir and expand it again to refresh file list. so ,why does treeview not refreshed when model is updated?

    thx in advance , sry for my english

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to refresh treeview when QFileSystemModel's filterList changed?

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to refresh treeview when QFileSystemModel's filterList changed?

    Qt Code:
    1. self.connect(self.findEdit, QtCore.SIGNAL("textChanged(const QString&)"),self.dirView.onFilterChanged)
    2.  
    3.  
    4. class DirView(QtGui.QTreeView):
    5. def __init__(self, dataSource):
    6. self.model = QtGui.QFileSystemModel(self)
    7. self.loadExtensionFilter()
    8. self.model.setFilter(QDir.AllDirs|QDir.Files | QDir.NoDotAndDotDot)
    9. self.model.setRootPath("/")
    10. self.setModel(self.model)
    11. def onFilterChanged(self,str):
    12. if str==QString(""):
    13. self.filterList.clear()
    14. for ext in self.extFilterList:
    15. self.filterList.append(ext)
    16. else:
    17. self.filterList.clear()
    18. for ext in self.extFilterList:
    19. self.filterList.append(QString("*"+ str) + ext)
    20.  
    21. self.model.setNameFilters(self.filterList)
    To copy to clipboard, switch view to plain text mode 
    so after i set new Filters by method setNameFilters(), the model is updated, but the treeview did not refresh.
    Last edited by vertusd; 24th November 2010 at 01:29.

  4. #4
    Join Date
    Jul 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to refresh treeview when QFileSystemModel's filterList changed?

    i tried QDirModel ,it worked fine, why treeview with QFileSystemModel can't refresh?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to refresh treeview when QFileSystemModel's filterList changed?

    Did the model really refresh?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jul 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to refresh treeview when QFileSystemModel's filterList changed?

    the model's NameFilters has changed( i print them after setNameFilters() ensure this ), but treeview did not refresh.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to refresh treeview when QFileSystemModel's filterList changed?

    I'm asking whether the model's data changed not whether the object's property value changed. The view probably didn't refresh because the model didn't change.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jul 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to refresh treeview when QFileSystemModel's filterList changed?

    sry for my misunderstanding ,the model's data did not changed, but when i change QFileSystemModel to QDirModel, treeview refreshed after NameFilters changed

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to refresh treeview when QFileSystemModel's filterList changed?

    Maybe QDirModel refreshes itself after name filters is changed and QFileSystemModel doesn't. I think it's high time to go beyond "it doesn't work for me" state. As for now you don't even know what doesn't work so how do you expect us to help you.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jul 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to refresh treeview when QFileSystemModel's filterList changed?

    thx for your patient.

    QDirModel refreshes itself after name filters is changed and QFileSystemModel doesn't
    i think this is why treeview did not refresh, i tried two ways to refresh treeview:
    1. make a new instance of QFileSystemModel, setModel this new instance and restore treeviews state, (it's a bit lag to restore expanded nodes, and it's a bit hard to restore node which colume number other than 0 )

    2. refresh the model Manually: i tried emit signal dataChanged() of model(give current index to it), but treeview did not refresh, may be i need to emit every node's dataChanged() signal
    Last edited by vertusd; 25th November 2010 at 04:56.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to refresh treeview when QFileSystemModel's filterList changed?

    Name filters is a filter method applied to existing nodes, it does not cause the whole model to be repopulated with new data. If you applied a name filter and it didn't change the data available in the model then it means the new filter reveals the same set of data as the old one. Which points us to a conclusion that you are doing something wrong in your code which causes two different filters to have the same result.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QFileSystemModel with checkboxes...
    By been_1990 in forum Qt Programming
    Replies: 14
    Last Post: 11th March 2011, 15:01
  2. Advanced QFileSystemModel
    By alexivanov91 in forum Qt Programming
    Replies: 0
    Last Post: 23rd September 2010, 09:23
  3. how use QFileSystemModel with QListView ?
    By lwifi in forum Qt Programming
    Replies: 4
    Last Post: 26th April 2010, 03:41
  4. Help with QFileSystemModel
    By TheShow in forum Qt Programming
    Replies: 4
    Last Post: 5th January 2010, 20:11
  5. QDirModel or QFileSystemModel?
    By ricardo in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2009, 17:10

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.