PDA

View Full Version : Qt::ItemIsDropEnabled ignored in dragDropMode QAbstractItemView::InternalMove



cheche
11th July 2010, 18:38
i have a QTreeWidget that looks like this:
http://bugreports.qt.nokia.com/secure/attachment/15889/15889_1.png
dragDropMode is QAbstractItemView::InternalMove
my problem is, that e.g. Row 2 can be dropped at Row 1 although Row 1 misses Qt::ItemIsDropEnabled:
http://bugreports.qt.nokia.com/secure/attachment/15890/15890_2.png

i just want the user to be able to move the items up/down by drag/drop but not to drop one item at another

norobro
12th July 2010, 01:32
Looks like it may be a bug in Qt Creator.

From the QTreeWidgetItem::flags() docs:
If the item was constructed with a parent, flags will in addition contain Qt::ItemIsDropEnabled.In the generated ui.h file the items are added with the treeWidget as parent and the items are definitely drop enabled, yet the property editor has DropEnabled unchecked.

If you were adding the items in your code you could unset the flag before you add the item to the treeWidget. When you add the items within Qt Creator the only way that I see to unset the flag is to iterate through the items.

Try adding something like the following to your treeWidget constructor:
for(int i=0; i<ui->treeWidget->topLevelItemCount(); ++i)
ui->treeWidget->topLevelItem(i)->setFlags(ui->treeWidget->topLevelItem(i)->flags() & ~Qt::ItemIsDropEnabled);