Hi all,
I have some problems about drag and drop.
Code snippet:
My aim is only when I drag some text data and drop over the textedit, the textedit shows the data.Qt Code:
{ if(event->mimeData()->hasText()) { event->acceptProposedAction(); qWarning("dragEnterEvent"); } } { //ui->textEdit->setPlainText(event->mimeData()->text()); event->acceptProposedAction(); qWarning("dropEvent"); } { if(event->answerRect().intersects(ui->textEdit->geometry())) { qWarning("dragMoveEvent_ignore_accept"); event->acceptProposedAction(); } else { event->ignore(); qWarning("dragMoveEvent_ignore"); } }To copy to clipboard, switch view to plain text mode
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
Bookmarks