Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Add a variable to QFileSystemModel
Forum Updated to NodeBB v4.3 + New Features

Add a variable to QFileSystemModel

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 719 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
    maxwell31
    wrote on last edited by
    #1

    Hi,

    I would like to make a derived class of QFileSystemModel which has one more variable/role to set the selection state of a file. Is there an easy way to do this?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Selections are normally not managed by the model but from the QItemSelectionModel in the view

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

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

        Yes this is true. But I have the problem, that I want to be able to sort my model, e.g. for the filename. If an item has been selected and I sort the model in the view, the selection stays at the place where it was and is not updated. E.g. if I have items 0 to 10 in alphabetical order and select item 1 and hit the sortingIndicator the items get sorted in inverse alphabetical oder and item one becomes 9, but selection stays at 1. I thought I try to solve this via adding the selection state to the model and later set the QItemSelectionModel indices according to my variable state.

        Is there an easier/better way to do it?

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

          https://forum.qt.io/topic/90202/treeview-of-qfilesystemmodel-remember-selection-after-sorting probably provides the answer for my actual problem. Just out of interest, would there be an easy way to add a variable to each item in a tree model?

          VRoninV 1 Reply Last reply
          1
          • M maxwell31

            https://forum.qt.io/topic/90202/treeview-of-qfilesystemmodel-remember-selection-after-sorting probably provides the answer for my actual problem. Just out of interest, would there be an easy way to add a variable to each item in a tree model?

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @maxwell31 In a generic tree model (like QStandardItemModel) yes, in QFileSystemModel you'd need a bit of hacking

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            2

            • Login

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