Many thanks for the reply @Jules, I really appreciate you taking the time to sweep up the un-answered threads!
As you say, I suspect the above is the wrong solution to my particular problem. I don’t specifically want my double-click Labels to go into edit mode when they gain focus; however, I do need to be able to tab traverse between the TextEditors of a list of double-click-able Labels once in edit mode and it seemed to me that calling showEditor() from focusGained() is the only easy way to achieve that…?
After several days reading & stepping through the Component / Label / TextEditor / KeyboardFocusTraverser code, I’m really struggling with creating the tab traversal behaviour I’m after:
- List of Labels (see GitHub example)
- Labels enter edit mode (only) on double-click
- Once in edit mode, tab/shift-tab traverses to the TextEditor of the next/previous sibling Label
- Escape / Return exits edit mode and returns focus to the Labels’ first parent Component which wantsKeyboardFocus
- Once edit mode is left, further tab/shift-tab traversal continues from the Labels’ parent
I’d expect to be able to use the FocusChangeType ‘cause’ argument of Label::focusGained to differentiate between a Label gaining focus on tab-traversal (Label should enter edit mode) vs on esc/enter (Label should return focus to parent). However when tab traversing between labels, focusGained gets called twice:
- First on the active TextEditor’s parent Label, with a cause of focusChangedDirectly
- Then on the sibling Label, with a cause of focusChangedByTabKey
And that first (superfluous?) change of focus is indistinguishable from the change of focus you get when using Escape / Enter to exit edit mode.
The comment at line 381 of Label.cpp rather implies that it is expected that the focus traverses directly from a Label’s TextEditor to the Label’s sibling (rather than via the label itself as described above):
// We'll use a custom focus traverser here to make sure focus goes from the
// text editor to another component rather than back to the label itself.
Any advice will be hugely appreciated!