Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTreeWidget - disable dropping on top level

Tags:

c++

qt

I have a QTreeWidget and I enabled the drag and drop. Despite I would like the users to be able to drag and drop items inside the tree I don't want them to drop any dragged item on the top level. How can I do that ?

Let's say that I have predefined categories which are the top level items and I don't want to extend that list. But in the lower levels the user can create any number of items and also she/he can move those items around.

like image 556
p.i.g. Avatar asked Sep 01 '25 17:09

p.i.g.


1 Answers

Thanks for the help. It worked.

MyTreeWidget::MyTreeWidget( QWidget* aParent /*= nullptr*/ )
: QTreeWidget( aParent )
{
// ...
    auto rooItem = invisibleRootItem();
    rooItem->setFlags( rooItem->flags() ^ Qt::ItemIsDropEnabled );
}
like image 53
p.i.g. Avatar answered Sep 04 '25 05:09

p.i.g.