PDA

View Full Version : Drop Rectangles: can't restrict drops to the textedit



cai
22nd October 2010, 03:03
Hi all,
I have some problems about drag and drop.
Code snippet:


void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
if(event->mimeData()->hasText())
{
event->acceptProposedAction();
qWarning("dragEnterEvent");
}
}
void MainWindow::dropEvent(QDropEvent *event)
{
//ui->textEdit->setPlainText(event->mimeData()->text());
event->acceptProposedAction();
qWarning("dropEvent");
}
void MainWindow::dragMoveEvent(QDragMoveEvent *event)
{
if(event->answerRect().intersects(ui->textEdit->geometry()))
{
qWarning("dragMoveEvent_ignore_accept");
event->acceptProposedAction();
}
else
{
event->ignore();
qWarning("dragMoveEvent_ignore");
}
}

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
http://pic.qnpic.com:83/r.jsp?fn=//qiannao/share/2010/10/22/-6355-83b7.PNG

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