Thank you for your answer.
So "what is this all about":
I have an application with lots of different widgets (treeviews, listviews, iconviews .... ). All widgest support dnd (all of them are still old qt3 style, but will/should (
) be "converted" soon). In my (derived) QTreeView I want do accept the drags from some of the other widgets, but not from all of the other widget. I thought the dragEnterEvent can (has to) be used for defining which events are accepted and which are not:
{
if ( e )
{
if ( e->provides("mystuff/mything") )
{
e->accept();
}
else
{
e->ignore();
}
}
}
void myQTListView::dragEnterEvent(QDragEnterEvent *e)
{
if ( e )
{
if ( e->provides("mystuff/mything") )
{
e->accept();
}
else
{
e->ignore();
}
}
}
To copy to clipboard, switch view to plain text mode
I also have different items (all derived from QTreeWidgetItem of course) in my treeview. Some of them accept drops and some of them don't. So I use the dragMoveEvent to get the "current dropping target" by calling
{
bool accept = false;
if ( item )
{
if ( dynamic_cast<MySpecialListViewItem*>(item) )
{
accept = true;
}
}
if ( accept )
{
e->accept();
}
else
{
e->ignore();
}
}
void myQTListView::dragMoveEvent(QDragMoveEvent *e)
{
QTreeWidgetItem *item = itemAt(e->pos());
bool accept = false;
if ( item )
{
if ( dynamic_cast<MySpecialListViewItem*>(item) )
{
accept = true;
}
}
if ( accept )
{
e->accept();
}
else
{
e->ignore();
}
}
To copy to clipboard, switch view to plain text mode
and check (by dynamic cast) if this (derived) QTreeWidgetItem is one of the items that accept drops.
I use the event->accept() or event->ignore() function to indicate if dropping is possible or not.
ps. Sorry that this has become a beginner tutorial on using drag and drop with QTreeViews, maybe I was running completely in the wrong direction?
Bookmarks