2
votes

I'm developing a Qt/C++ app with a QTreeWidgetItem. When a new item is created I set it setEditable and it allow me to fill directly in the UI the new name.

I'm currently using itemChanged as shown below to catch the change and save it. By default, I set the new item name to new folder and after I can change it manually. My issue is when I'm creating the item, it becomes editable and if I press Enter or Esc without any changes, the itemChanged is not generated.

Is there a command I can use based on SIGNAL/SLOT which can catch the Enter/Esc event. The goal is to triggered the same signals

connect(this, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
        this, SLOT(onTreeItemChanged(QTreeWidgetItem*)));

I want to connect Enter/Esc signals to onTreeItemChanged as it's done for itemChanged.

I have tried the use of itemActivated, but it's not triggered even if Enter is pressed.

connect(this, SIGNAL(itemActivated(QTreeWidgetItem*, int)),
        this, SLOT(onTreeItemChanged(QTreeWidgetItem*)));

Any idea,

Seb

1
nop this is why I have added that the event is not triggeredSeb

1 Answers

0
votes

Sorry to write this in answer, but i still cant comment:

I had some (maybe) similar problems concerning a class derived from QCombobox, which had some spetial behaviour, when to show the popup and when not to.

Everytime Return was pressed domething happend but it wasent a QEventKeyEvent, the solution was to catch QEvent::Shortcut, because the element interpreted this key as shortcut for accept.

-- EDIT -- In such cases i often install a event fiolter and let it just write the events to the output, using a switch statement to filter out uninteresting elements, till i get the culprit.