Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSortFilterProxyModel - refresh TreeNode on delete/add
QtWS25 Last Chance

QSortFilterProxyModel - refresh TreeNode on delete/add

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    ManasQt
    wrote on last edited by
    #1

    Hi ,
    I have developed a model based on QSortFilterProxyModel and so far it works well. I have an option called 'Refresh Folder' in Contextmenu of the QTreeView.

    Refresh Folder- needs to updates the parent TreeNode with newly added child Nodes (reading from the disk at particular location).

     When i filter nodes based on some regular expression it displays desired Nodes. In the mean while i want to refresh/Reload/update the folder node if there are any new files exists at parent directory then i have to update the Parent TreeNode and filter it again as user typed filtered text.
    

    But in my case , When the user tries to refresh a Parent TreeNode when it is in filtered mode TreeView displays duplicate Nodes.How to solve this?/////

    Note: QTreView allows Updates/Refresh/Reload a perticular Folder Node properly when there is no filtered text

    How to update/Refresh a Folder TreeNode when Filter is on?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      I am currently not sure, where the bug could be located.
      Can you show us some of your code, especially the model and the QSPPM you have?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        ManasQt
        wrote on last edited by
        #3

        Hi Girolf,
        In my 'RefreshFolder' method inside treeview class which inherits QTreeView and here is the code.
        please let me know if you need more info.

        @def RefreshFodler(self):
        model=self.model()
        index=self.selectionModel().currentIndex()
        data=self.getData(index) # returns custom data with
        item=self.originalmodel.itemFromIndex(index)
        model.removeRows(0,item.rowCount(),index)
        """ here i am reading files from disk and updating the item"""
        files=self.getFiles()
        self.setupModelData(files,item)#---adds file to parent-item
        item.sort(0,QtCore.Qt.AscendingOrder)
        self.update()
        if item.hasChildren():
        self.expand(index)

        def getData(self,index):
        index=self.sortmodel.mapToSource(index)
        item=self.originalmodel.itemFromIndex(index)
        return item.data(0,QtCore.Qt.UserRole)

        @

        1 Reply Last reply
        0
        • M Offline
          M Offline
          ManasQt
          wrote on last edited by
          #4

          Hi Gerolf,
          I think i found the problem let me solve and let you know.

          problem was with ---model.removeRows(0,item.rowCount(),index)
          solution -- item.removeRows(0,item.rowCount())
          thanks

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved