PDA

View Full Version : Control Drag Operation



sajis997
19th January 2012, 17:35
Hello forum,

I am attaching an image where i have loaded a tree item into the tree view . Each of the item are draggable into the scene. But some of the tree items are not draggable based on their internal characteristics.

How can i do this ? I tried the following




if(node->getAbstract())
setAcceptDrops(false);


But i can drag the item which is supposed to be non-draggable.


Any hint?

Please Look at the attachment

Regards
Sajjad

Spitfire
20th January 2012, 17:33
Try

void TreeWidget::mousePressEvent( QMouseEvent* e )
{
this->draggedItem = item_you_will_drag;
QTreeWidget::mousePressEvent( e );
}

void TreeWidget::dragLeaveEvent( QDragLeaveEvent* e )
{
if( this->draggedItem->getAbstract() )
{
e->setDropAction( Qt::IgnoreAction );
}
else
{
e->acceptProposedAction();
}

QTreeWidget::dragLeaveEvent( e );
} This way the drop will be ignored on items that return true from getAbstract().

sajis997
25th January 2012, 22:13
Hi forum,


I did it in the dragEnterEvent instead. What is the basic difference between these dragLeaveEvent() and dragEnterEvent() these two ?

And it works fine the way i wanted, thanks for the hint .




void Editor::dragEnterEvent(QDragEnterEvent *event)
{
if(event->mimeData()->hasText())
{
//get the node factory
NodeFactory *l_nodeFactory;
NodeData *l_node;

if(Singleton<NodeFactory>::isInited())
{
//get the pointer for the factory
l_nodeFactory = Singleton<NodeFactory>::getPtr();

l_node = l_nodeFactory->getNodeData(event->mimeData()->text());

if(!l_node->getAbstract())
{
event->setDropAction(Qt::CopyAction);
event->accept();
}
else
{
event->setDropAction(Qt::IgnoreAction);
}
}
}
else
event->ignore();
}

Spitfire
26th January 2012, 13:10
I don't know what your app is doing but if it's supposed to work with only internal structures, see what happens when you drag some text from other application onto it.

As to the difference - it's simple.
Drag enter handler is triggered when drag enter the widget, drag leave handler is triggered when drag leaves the widget.
Look up Drag and Drop in documentation for more details.