Unable to edit custom treeview with custom proxy and model: `editing failed`
-
Hi,
I have inherited from
QTreeView,QAbstractItemModeland fromQSortFilterProxyModel. It is pretty much of code there but everything work except callingedit()from my custom tree. I get warning: edit: editing failedI understand that somehow the function edit(index, trigger, event (or shouldEdit()) fails but I can't understand why could tht be.
I have tried it with and without custom item delegate (inherited from
QStyledItemDelegate), tried to set different edit triggers but still no luck. The model has flags (and probably some other):Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;There is a thing: no matter what edit trigger I set (even double click) I still can see that by double click items either get expanded or collapsed.
I need to invokeedit()in slot invoked by some action:void MyTreeView::init(){ setSortingEnabled(true); setSelectionMode(QAbstractItemView::ExtendedSelection); setContextMenuPolicy(Qt::CustomContextMenu); header()->setContextMenuPolicy(Qt::CustomContextMenu); setDragDropMode(QAbstractItemView::DragDropMode::DragDrop); setDragEnabled(true); setAcceptDrops(true); setDropIndicatorShown(true); MyDelegate* itDelegate = new MyDelegate(this); this->setItemDelegate(itDelegate); MyProxy* proxy = new MyProxy(this); MyModel* model = new MyModel(proxy); proxy->setSourceModel(model); this->setModel(proxy); QAction *renameAction = menu->addAction("Rename object"); connect(renameAction, &QAction::triggered, this, &MyTreeView::onRenameObject); ... } void MyTreeView::onRenameObject(){ this->edit(currentIndex()); }openPersistentEditor()works but I hope I solve the problem usinedit()function.
At the time whenedit()is called the view state isQAbstractItemView::NoState.What i'm missing?
-
I'm idiot I missed
Qt::ItemIsEditableflag...Don't know how it is possible to look at many times flags, even write them on the forum and still miss it... I hope I'm not alone :)