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. QTreeView dropping on item - filtering ?
QtWS25 Last Chance

QTreeView dropping on item - filtering ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtreeviewqdragqdrop
6 Posts 2 Posters 1.2k 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 17 Mar 2019, 12:16 last edited by
    #1

    Hey

    So say I have a QTreeView with 10 entries, they are different types, say groups,pictures,text,some switches etc etc.

    Some of them can have children, other not, and some can have only specific type of child.

    Does QT offer any way of virtualization to override what gets accepted what not on drop event?

    I can see that in private class the :

           inline bool canDrop(QDropEvent *event) {}
    

    Decides if it gets accepted or not, but that's not virtual and I wonder if I'm too deep in source and missing the obvious system...

    Regards
    Dariusz
    TIA

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 17 Mar 2019, 13:20 last edited by
      #2

      The filtering is done by the model, not the view. In your model implementation override canDropMimeData and return a bool indicating if given entry can accept the drop.

      1 Reply Last reply
      3
      • D Offline
        D Offline
        Dariusz
        wrote on 17 Mar 2019, 14:09 last edited by
        #3

        @Chris-Kawa said in QTreeView dropping on item - filtering ?:

        canDropMimeData

        Uuuuuuuuuuuuu I knew I was overengineering it! Thanks! By the sounds of dots this sounds like what I need... Yay!

        Thanks, will "Solve topic" in a little while once I give it a go... In case I fail.

        Regards
        Dariusz

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dariusz
          wrote on 19 Mar 2019, 19:07 last edited by
          #4

          Hey

          Ok so this work great thanks!

          But... a side question... is there a way to override Qt default margin detection of where I want to drop the item? Right now its based on size of items or something like that, I would like to create my own sizing rule of detection. I find it quite "hard" to drop items in certain scenarios in place where I want to...

          Any hints?

          Regards
          Dariusz
          TIA

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on 19 Mar 2019, 19:48 last edited by
            #5

            There's no customization point intended for that from what I know. This detection is implemented in the view class in an overriden dragMoveEvent(). The implementation uses indexAt() and dropIndicatorPosition().

            The dragMoveEvent() and indexAt() are virtual, so, depending on how much you want to customize it, you might be able to do it by overriding them, but I fear it's gonna be difficult without being able to modify dropIndicatorPosition() too and considering that those overrides manipulate some internal view states. Basically you would have to trick it somehow i.e. by overriding those methods, fixing up some "fake" state and calling base implementation.

            1 Reply Last reply
            1
            • D Offline
              D Offline
              Dariusz
              wrote on 20 Mar 2019, 18:24 last edited by
              #6

              I've wrote 1 treeView/model system last year that had it all re-implemented from scratch, a few days ago I decided to rewrite it to increase performance and relay more on native functions of QT. Which I did and works great but the margin thing is a sticking point. I remember how much work it was before to get it to work properly... took a while as I had to write quite a few functions before I got to the point of margin detection. I'm very surprised there is no

              margin = (qt code ) + userMarginOverrideVal

              in the canDrop() function... this would have allowed us to just say, hey add +5 pixels to detection or something like that...

              Perhaps I should add it to feature request, would posting it in a bug report tracker be a good place? I don't see feature requests and I have no idea how to get the source to compile (Just didn't spend enough time on it) and add it myself & post to qt as commit...

              As far as I can tell we need like 2 functions, setOverrideMargin(int val) and getOverrideMargin(), skipping setting flag true/false if we want to use it as defaultVal should just be 0...

              TIA

              1 Reply Last reply
              0

              4/6

              19 Mar 2019, 19:07

              • Login

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