0

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 :(

Dan Forever
  • 381
  • 2
  • 12
  • What about handling `QAbstractItemView::doubleClicked()` and `QAbstractItemView::clicked()` signals? – vahancho Jun 24 '20 at 09:32
  • Well `doubleClicked()` means the item is "opened" only via mouse input (user can't use keyboard navigation) And my original plan was to use clicked, and add in a timer that manually checks to see if the user clicks a second time, before allowing the user to rename the item. But looking at the API, I feel like support for this is already there, but maybe I'm just not seeing it? (Or maybe it's designed exclusively for in-line editing and won't cooperate with other functionality you may have planned?) – Dan Forever Jun 24 '20 at 13:29

0 Answers0