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. Model, view and delegate help
QtWS25 Last Chance

Model, view and delegate help

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 696 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
    Mr Gisa
    wrote on last edited by
    #1

    I have a class that is called BookContent, this book can be a file or a zip archive with files in it. In that class I have the authors name, and an enum member that says if the BookContent class is a File or Archive. BookContent can have multiple book children, meaning that if a Book is an Archive it will have a collection of Book as File inside.

    I have a collection of BookContent so I was wondering how can I list that in a tree view, but the thing is, if BookContent is a Archive I want to put a button (See) in the tree view along side that item and when the user clicks on that button, calls a method.

    That method that the user clicked will make an operation to get the zip archive contents and then create another BookContent for each one with the type of File and put as children for the clicked item on the tree view.

    0_1525704220948_fcb5e959-6f62-466d-9e17-db62244452ed-image.png

    Something like that.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      Hi @Mr-Gisa

      Why not use a treeView the standard way.

      In your case, the "see" button serves nothing because it's the exact function of the triangle at the beginning of a row in a treeWiew.
      When the user click on the triangle, the tree expands to show the item contents.

      All you have to do is to listen to the expand() signal and act accordingly.

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

        But the triangle appears only if it has children, right?

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

          I think your can return true here:

          bool QAbstractItemModel::hasChildren(const QModelIndex &parent = QModelIndex()) const
          

          even if there is no children yet.

          When you receive the expend() signal, you unzip the file if it's not already done, and then update the model

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mr Gisa
            wrote on last edited by
            #5

            The thing is that I wanted the expand triangle to appear after the extraction, because if I do the way you pointed out I will have to check if it has been extracted already and put more code in the overridden model class method and I think that adding a custom delegate to draw a button with a signal with clicked is easier, idk. What you think?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mpergand
              wrote on last edited by
              #6

              At first think, i would say you need to memorize the state unzipped or not.
              But in fact, when you receive the expand signal, if the parent is a zip file and it has no children, then it means an unzip operation is needed.

              I never did this kind of thing, but i don't see any issue - may be i'm wrong, nasty bug always lurking around ;)

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mr Gisa
                wrote on last edited by
                #7

                I will try something with the tree list example that comes with Qt and also reading a few things on the internet. Anything I will be back here.

                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