Results 1 to 8 of 8

Thread: drop event becomes invalid

  1. #1
    Join Date
    Jul 2013
    Posts
    72
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default drop event becomes invalid

    Using drag and drop to drag tree item to a QwtPlot, sometimes the event becomes invalid.

    Please help. Below is the my code about drag and drop.

    Qt Code:
    1. Drag starts:
    2.  
    3. void DataTree::mouseMoveEvent(QMouseEvent *event)
    4. {
    5. if (m_currentItem) {
    6. QString name = m_currentItem->text(TITLE_COLUMN);
    7. QString seq = m_currentItem->text(ID_COLUMN);
    8. QString type = m_currentItem->text(TAG_COLUMN);
    9. QString code = m_currentItem->text(CODE_COLUMN);
    10.  
    11. if (code.length() == 8) {
    12. QTreeWidgetItem *parentItem = m_currentItem->parent();
    13. QString fileName = parentItem->text(TAG_COLUMN);
    14.  
    15. // Prepare for dragging
    16. QDrag *drag = new QDrag(this);
    17. QMimeData *mimeData = new QMimeData;
    18. QByteArray byteArray;
    19. QDataStream dataStream(&byteArray, QIODevice::WriteOnly);
    20. dataStream << fileName << name << seq << type;
    21.  
    22. QSize size(30,30);
    23. QPixmap widgetImage = m_currentItem->icon(0).pixmap(size);
    24. drag->setPixmap(widgetImage);
    25. mimeData->setData("curveData/x-curveData", byteArray);
    26. drag->setMimeData(mimeData);
    27.  
    28. drag->setHotSpot(QPoint(15,15));
    29. if (!(drag->exec(Qt::MoveAction) == Qt::MoveAction))
    30. {
    31. // event->ignore();
    32. ;
    33. }
    34. }
    35.  
    36. void DataTree::dragEnterEvent(QDragEnterEvent *event)
    37. {
    38. if (event->mimeData()->hasFormat("curveData/x-curveData"))
    39. {
    40. event->acceptProposedAction();
    41. event->accept();
    42. }
    43. else
    44. {
    45. event->ignore();
    46. }
    47. }
    48.  
    49.  
    50. void DataTree::dragMoveEvent(QDragMoveEvent *event)
    51. {
    52. if( event->mimeData()->hasFormat("curveData/x-curveData")){
    53. event->acceptProposedAction();
    54. event->accept();
    55. }
    56. else
    57. {
    58. event->ignore();
    59.  
    60. }
    61.  
    62. }
    63.  
    64. Accept drop:
    65.  
    66. void Plot::dropEvent(QDropEvent *event)
    67. {
    68. if (event->mimeData()->hasFormat("curveData/x-curveData")) {
    69. QByteArray byteArray = event->mimeData()->data("curveData/x-curveData");
    70. QDataStream dataStream(&byteArray, QIODevice::ReadOnly);
    71.  
    72. QString fileName;
    73. QString name ;
    74. QString seq;
    75. QString type;
    76.  
    77. dataStream >> fileName >> name >> seq >> type;
    78.  
    79. emit addCurve(fileName, name, seq, type, this);
    80. event->acceptProposedAction();
    81. event->accept();
    82.  
    83. } else {
    84. event->ignore();
    85. }
    86. }
    87.  
    88. void Plot::dragEnterEvent(QDragEnterEvent *event)
    89. {
    90. if ( event->mimeData()->hasFormat("curveData/x-curveData")) {
    91. event->setDropAction(Qt::MoveAction);
    92. event->accept();
    93. } else {
    94. event->ignore();
    95.  
    96. }
    97. }
    98.  
    99. void Plot::dragMoveEvent(QDragMoveEvent *event)
    100. {
    101.  
    102. if (event->mimeData()->hasFormat("curveData/x-curveData")) {
    103. event->setDropAction(Qt::MoveAction);
    104. event->accept();
    105. } else {
    106. event->ignore();
    107. }
    108. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 30th March 2014 at 12:34. Reason: change [quote] to [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: drop event becomes invalid

    What do you mean with "it becomes invalid"?
    Where in your code does that lead to a problem?

    Cheers,
    _

  3. #3
    Join Date
    Jul 2013
    Posts
    72
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: drop event becomes invalid

    When I drag an tree item to my plot, I'm sure the drag event was triggered since the mouse was moving with the item icon which I set as the drag picture. But when releasing the mouse which should had triggered the drop event, nothing happened.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: drop event becomes invalid

    Do you get the drag enter and move events?

    Cheers,
    _

  5. #5
    Join Date
    Jul 2013
    Posts
    72
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: drop event becomes invalid

    yeah, both of drag enter and move events are accepted. But no drop event .

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: drop event becomes invalid

    Ah, so the problem is that Plot::dropEvent() is not called, not that it is called with an invalid event, right?

    Have you switched the widget's acceptDrop property to true?

    Cheers,
    _

  7. #7
    Join Date
    Jul 2013
    Posts
    72
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: drop event becomes invalid

    this->setAcceptDrops(true);

    I have set this property, the problem above happens occasionally. The program runs fine most of the time.

  8. #8
    Join Date
    Jul 2013
    Posts
    72
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: drop event becomes invalid

    what else can I do?

Similar Threads

  1. Replies: 1
    Last Post: 5th February 2014, 09:17
  2. Replies: 2
    Last Post: 13th October 2010, 21:51
  3. Replies: 0
    Last Post: 4th May 2010, 10:24
  4. qtreewidget and drop event detection
    By eric_vi in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2010, 11:20
  5. Replies: 2
    Last Post: 24th October 2009, 23:45

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.