1
votes

I have a QTreeWidget for which I want double click to open a specific thing and single click to start renaming of the item, but I don’t want both actions to happen when I double click. Right now when I double click my tree item I get my things to load and the item gets in a renaming state.

I am using the following statements to set my QTreeWidget:

this->setEditTriggers(
    QAbstractItemView::EditKeyPressed
    | QAbstractItemView::SelectedClicked
);
connect(
    this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
    this, SLOT(OnMouseDoubleClicked(QTreeWidgetItem*, int))
);

Is there something specific I could do to prevent the item to get in a renaming/edit state when I double click on it since I only want my custom loading action to happen, but still keep in-place edit when I single click an element in the tree?

1
I'm sorry, but I think that Your approach is wrong. By design Double Click should be extension of One Click. For example: One Click - select, Double Click - Open or Rename. There are two reasons: First - to not confuse users. Second - it easier to implement. I think you should rethink Your logic.firescreamer
possible duplicate of this questionazf
At first I didn't have this->setExpandsOnDoubleClick(false);, after validation it seems to work. Still letting the question open if someone has a better approach to suggest. @HostileFork: thanks for the question editing.Jonathan Schmidt
@JonathanSchmidt Sure...just keep an eye on the preview and try not to wrap things so people need to drag a scroll bar to read your code in the future, it's a "speed bump". Also: It's perfectly OK on StackOverflow to answer your own question and accept it. That's what I'd do in this case...edit the question back as it was, and answer it with this->setExpandsOnDoubleClick(false) and accept your own answer. It's not eternally binding; someone who comes along later with an alternative viewpoint can add it, you can accept it. But closing a question gets it out of "unanswered" searches.HostileFork says dont trust SE

1 Answers

1
votes

Actually if you add

this->setExpandsOnDoubleClick(false);

It fixes two issues at the same time, first when you double click on any item, items with children don't get automatically expanded, which is what we wanted, and most important, the item don't get in the state of in-place renaming/edition.