2

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

Seb
  • 2,929
  • 4
  • 30
  • 73
  • [This question looks like it may solve your issue](http://stackoverflow.com/questions/14538057/catch-esc-key-press-event-when-editing-a-qtreewidgetitem) – GPPK Mar 05 '15 at 17:20
  • nop this is why I have added that the event is not triggered – Seb Mar 06 '15 at 01:59

1 Answers1

0

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.

edisn
  • 58
  • 11
  • I was able to see the QEventKeyEvent. – Seb Mar 08 '15 at 16:06
  • I dont see a easy solution for tha one, Maybe you could use the **currentIndex ()** (inherited from QAbstractItemView) to get the item index and use it in a custom signal when the **QAbstractItemDelegate * itemDelegate ()** fires a **closeEditor**? This is a guess but the delegate schould fire this signal when the editor closes (no matter if it is Return/escape or clicking somewhere else, maybe you want to use a filter on the delegate to only get the key). The currentItem schould return the Item that had the editor open, and you could implement a signal my_itemChanged(QTreeWidgetItem*). – edisn Mar 09 '15 at 17:30
  • When the item is created with the coorect name (without changing) edited wont fire, (you might get a item added but i supose you only want to act after the editor-delegate has ben closed.) – edisn Mar 09 '15 at 17:32
  • yes you are right but I can manage to change the itemChanged to an editor closed in that case it will be the same for me – Seb Mar 09 '15 at 23:49
  • Thanks. I have tried to subclass Keyevent but issue is that the event is generated before the new value entered is treated by QTreeWIdgetItem. In that case I catch the event but too early – Seb Mar 16 '15 at 19:54