Results 1 to 6 of 6

Thread: QTreeView - drop indicator not showing for an external drag from another tree view

  1. #1
    Join Date
    Dec 2011
    Posts
    48
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTreeView - drop indicator not showing for an external drag from another tree view

    I have the drag and drop indicators working fine for internal moves within the same tree view (say TreeView1).

    But, the indicators are not visible when dragging from an external tree view (TreeView2 -> TreeView1).

    Any idea what is needed to show the drop indicators when dragging from an external tree view?

    Here's my code for the tree view that is the drop target.

    Qt Code:
    1. void MyTreeView::dragMoveEvent(QDragMoveEvent *event)
    2. {
    3. // Call base class -- this shows the drop indicators
    4. QTreeView::dragMoveEvent(event);
    5.  
    6. if (event->mimeData()->hasFormat("text/plain") )
    7. {
    8. event->acceptProposedAction();
    9. event->accept();
    10. }
    11. else
    12. {
    13. event->ignore();
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by alketi; 3rd March 2015 at 22:17.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeView - drop indicator not showing for an external drag from another tree vie

    Basically all you need to do is implement drag&drop related functions in the model. You don't have to do anything with the view.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2011
    Posts
    48
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeView - drop indicator not showing for an external drag from another tree vie

    Hi wysota, thank you, but maybe I wasn't clear enough --

    Drag & drop works, both internal to the tree view and from one tree view to another.

    -- When dragging (moving) a row internally, I see the drop indicators.

    -- When dragging (copying) a row from an external tree view, I do not see the drop indicators (but the drop action still works).

    My question is how do I show the drop indicators when dropping from one tree view to another tree view?? (I see them when dropping within the same tree view)

    Thank you.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeView - drop indicator not showing for an external drag from another tree vie

    My question is how do I show the drop indicators when dropping from one tree view to another tree view??
    You do that by properly implementing drag&drop operations in the models without modifying the views.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2011
    Posts
    48
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeView - drop indicator not showing for an external drag from another tree vie

    wysota, none of the overridden methods: flags(..), supportedDropActions(..), etc. in TreeModel #2 are getting called when the dragging begins from TreeModel #1.

    I assume that's why the indicator isn't appearing. I can still successfully make the drop, but I don't see the indicator....

    When dragging&dropping internally in TreeModel #2, all the overridden methods are called, and the indicator appears.

    Can you provide some clue as to what needs to be implemented to see the indicator when dragging from TreeModel #1 into TreeModel #2?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeView - drop indicator not showing for an external drag from another tree vie

    Quote Originally Posted by alketi View Post
    wysota, none of the overridden methods: flags(..), supportedDropActions(..), etc. in TreeModel #2 are getting called when the dragging begins from TreeModel #1.
    You should implement QAbstractItemModel::mimeTypes(), QAbstractItemModel::mimeData(), QAbstractItemModel::canDropMimeData() and QAbstractItemModel::dropMimeData(). As well as flags(), of course.

    Can you provide some clue as to what needs to be implemented to see the indicator when dragging from TreeModel #1 into TreeModel #2?
    You read "Using Drag and Drop with Item Views", didn't you?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Drag and drop from list/tree widget to graphics view
    By chaltier in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2012, 04:15
  2. Drag and Drop indicator Position
    By whitefurrows in forum Qt Programming
    Replies: 1
    Last Post: 14th July 2011, 11:35
  3. Replies: 2
    Last Post: 13th October 2010, 21:51
  4. Replies: 0
    Last Post: 4th May 2010, 10:24
  5. Drag and drop indicator
    By iswm in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2007, 18:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.