Hi all,
I have some problems about drag and drop.
Code snippet:
Qt Code:
  1. void MainWindow::dragEnterEvent(QDragEnterEvent *event)
  2. {
  3. if(event->mimeData()->hasText())
  4. {
  5. event->acceptProposedAction();
  6. qWarning("dragEnterEvent");
  7. }
  8. }
  9. void MainWindow::dropEvent(QDropEvent *event)
  10. {
  11. //ui->textEdit->setPlainText(event->mimeData()->text());
  12. event->acceptProposedAction();
  13. qWarning("dropEvent");
  14. }
  15. void MainWindow::dragMoveEvent(QDragMoveEvent *event)
  16. {
  17. if(event->answerRect().intersects(ui->textEdit->geometry()))
  18. {
  19. qWarning("dragMoveEvent_ignore_accept");
  20. event->acceptProposedAction();
  21. }
  22. else
  23. {
  24. event->ignore();
  25. qWarning("dragMoveEvent_ignore");
  26. }
  27. }
To copy to clipboard, switch view to plain text mode 
My aim is only when I drag some text data and drop over the textedit, the textedit shows the data.
As the picture below, I drag the mouse along 1-2-3-4-5-6, and release the mouse on 6(textedit). The application output is:
dragEnterEvent ->1
dragMoveEvent_ignore
dragEnterEvent
dragMoveEvent_ignore
dragEnterEvent ->2
dragMoveEvent_ignore_accept
dragEnterEvent ->3
dragMoveEvent_ignore
dragEnterEvent ->4
dragMoveEvent_ignore_accept
dragEnterEvent ->5
dragMoveEvent_ignore
dragEnterEvent ->6
dragMoveEvent_ignore_accept


1. When the mouse is over the toolbutton and calendarWidget, they accept the proposed drop actions. I have restricted drops to the textedit, but it didn’t work. Why?
2. When I release the mouse over the textedit, the dropEvent is not sent. Does the dropEvent not send every time when a drag and drop action is completed? I don’t set the data to the textedit, but it shows the text when I drop over it. Why?

Regards