[Qt-interest] what is that difference between event->accept() and event->acceptProposedAction()

Stephen Kelly steveire at gmail.com
Sat Jan 3 01:17:48 CET 2009


ami guru wrote:

> Hello forum,
> 
> According to the manual there is
> 
> "
> 
> Once you have supplied a replacement drop action, call accept() instead of
> acceptProposedAction <qdropevent.html#acceptProposedAction>().
> 
> "

Hi,

I find this confusing too, and recently ran into a bug in it.

http://thread.gmane.org/gmane.comp.lib.qt.general/8765

proposedAction is the action that the drag was initialised with. The docs
are still a little unclear I think. I think the proposed action defaults to
a copy action. Calling accept() tells qt that the action has been handled,
and is not still 'pending' to be handled in a super class or another event
handler. 

I think you only call accept() if you actually handle performing the action.
In your case, you'd handle putting the fridge magnet in place and then call
accept.

You can check what the proposed action is with proposedAction(), and either
accept that, or set a new action and then call accept. In your case, you
only have to do setDropAction if the proposed action is different to what
you want.

Hopefully if I'm wrong someone will teach us both a lesson.

Cheers,

Steve.

> 
> in the following example the drop action has been  over-ridden.
> 
> 
> ******************************************
> 
>     if (event->mimeData()->hasFormat("application/x-fridgemagnet"))
>       {
>         if (children().contains(event->source()))
>       {
>             event->setDropAction(Qt::MoveAction);
>         /*
>           specifies that
>           the future move will
>           be acceptable
>          */
>             event->accept();
>       }
>     else
>       {
>             /*
>               is that ok if event->accept() is used instead?
>             */
>             event->acceptProposedAction();
>       }
>       }
>     else if (event->mimeData()->hasText())
>       {
>         event->acceptProposedAction();
>       }
>     else
>       {
>         event->ignore();
>       }
> 
> 
> *****************************************
> 
> 
> 
> Regards
> Sajjad




More information about the Qt-interest-old mailing list