Results 1 to 4 of 4

Thread: Control Drag Operation

  1. #1
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Control Drag Operation

    Hello forum,

    I am attaching an image where i have loaded a tree item into the tree view . Each of the item are draggable into the scene. But some of the tree items are not draggable based on their internal characteristics.

    How can i do this ? I tried the following


    Qt Code:
    1. if(node->getAbstract())
    2. setAcceptDrops(false);
    To copy to clipboard, switch view to plain text mode 

    But i can drag the item which is supposed to be non-draggable.


    Any hint?

    Please Look at the attachment

    Regards
    Sajjad
    Attached Images Attached Images

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Control Drag Operation

    Try
    Qt Code:
    1. void TreeWidget::mousePressEvent( QMouseEvent* e )
    2. {
    3. this->draggedItem = item_you_will_drag;
    4. QTreeWidget::mousePressEvent( e );
    5. }
    6.  
    7. void TreeWidget::dragLeaveEvent( QDragLeaveEvent* e )
    8. {
    9. if( this->draggedItem->getAbstract() )
    10. {
    11. e->setDropAction( Qt::IgnoreAction );
    12. }
    13. else
    14. {
    15. e->acceptProposedAction();
    16. }
    17.  
    18. QTreeWidget::dragLeaveEvent( e );
    19. }
    To copy to clipboard, switch view to plain text mode 
    This way the drop will be ignored on items that return true from getAbstract().

  3. The following user says thank you to Spitfire for this useful post:

    sajis997 (25th January 2012)

  4. #3
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Control Drag Operation

    Hi forum,


    I did it in the dragEnterEvent instead. What is the basic difference between these dragLeaveEvent() and dragEnterEvent() these two ?

    And it works fine the way i wanted, thanks for the hint .


    Qt Code:
    1. void Editor::dragEnterEvent(QDragEnterEvent *event)
    2. {
    3. if(event->mimeData()->hasText())
    4. {
    5. //get the node factory
    6. NodeFactory *l_nodeFactory;
    7. NodeData *l_node;
    8.  
    9. if(Singleton<NodeFactory>::isInited())
    10. {
    11. //get the pointer for the factory
    12. l_nodeFactory = Singleton<NodeFactory>::getPtr();
    13.  
    14. l_node = l_nodeFactory->getNodeData(event->mimeData()->text());
    15.  
    16. if(!l_node->getAbstract())
    17. {
    18. event->setDropAction(Qt::CopyAction);
    19. event->accept();
    20. }
    21. else
    22. {
    23. event->setDropAction(Qt::IgnoreAction);
    24. }
    25. }
    26. }
    27. else
    28. event->ignore();
    29. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Control Drag Operation

    I don't know what your app is doing but if it's supposed to work with only internal structures, see what happens when you drag some text from other application onto it.

    As to the difference - it's simple.
    Drag enter handler is triggered when drag enter the widget, drag leave handler is triggered when drag leaves the widget.
    Look up Drag and Drop in documentation for more details.

Similar Threads

  1. QTreeView find out when the drag operation ends
    By mentalmushroom in forum Qt Programming
    Replies: 2
    Last Post: 4th October 2011, 07:37
  2. Replies: 0
    Last Post: 4th May 2010, 10:24
  3. Replies: 0
    Last Post: 16th December 2009, 09:45
  4. Opposite of |= operation
    By JPNaude in forum Qt Programming
    Replies: 5
    Last Post: 16th November 2009, 12:33
  5. file operation
    By jay in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2009, 11:19

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.