I'm trying to create behaviour in my program similar to windows file explorer, where double clicking (or pressing enter on the keyboard when it's selected and in focus) on an item in my QAbstractItemView
will "open" that item in a new window, and single clicking on the item (when it's already selected) will allow the user to rename that item with a little in-place text field.
Unfortunately, my various attempts at getting this to work either result in both happening on double click, or only one or the other works at all.
This is my best attempt so far:
// Create QTreeView instance
m_myTree = ...;
m_myTree->setEditTriggers(QAbstractItemView::SelectedClicked);
connect(m_myTree , &QAbstractItemView::activated, []{ /* Open dialog here */ });
I've also tried overriding void QAbstractItemView::edit(const QModelIndex& index, QAbstractItemView::EditTrigger trigger, QEvent* event)
but using that to filter out QAbstractItemView::DoubleClicked
from the trigger
parameter doesn't seem to accomplish much :(