[Qt-interest] prevent a drop in QTreeWidget
Ross Bencina
rossb-lists at audiomulch.com
Fri May 27 12:22:25 CEST 2011
Graham Labdon wrote:
if (index.row() > 1 || (index.row() == 1 && dropIndPosition ==
QAbstractItemView::BelowItem))
{
QAbstractItemView::dropEvent(event);
}
else
{
event->setDropAction(Qt::IgnoreAction);
event->accept();
}
}
> The problems I have are
> 1. I cannot move an item to the bottom of the tree (in this case
> dropIndicatorPosition is OnViewport)
Well you'll have to allow OnViewport in the first branch of your if
statement then. You could check the pos().x() to know if you're above or
below the items (I think I get the top of the first item using
QAbstractItemView::visualRect and compare the event pos.x against that).
> 2. If an item has subitems - when I move the item the subitems are removed
That, I'm afraid, I know nothing about. I'm not sure if the default
drag-and-drop mechanism supports deep copying of items. You might want to
post a new question and give details of the Model implementation you're
using.
Ross.
More information about the Qt-interest-old
mailing list