QTreeView dropping on item - filtering ?



  • 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


  • Moderators

    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.



  • @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



  • 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


  • Moderators

    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.



  • 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


Log in to reply