Focus problems

I have a weird problem. I have to a TextEditor within another component, along with some other components like sliders etc., and when I click on of these sliders to adjust it, for some reason the TextEditor gains focus and becomes editable. This looks and feels really weird and I would like to avoid it.

Is it possible to turn the automatic focus stuff off completely? I only want TextEditors to gain focus if they are clicked on, not tabbed through or other such actions. It should NEVER be automatic for my plugin.

What’s the easiest way to achieve this?

This seems related to Text Editor loses focus when it should not.

Sounds different to me. It doesn’t lose focus, my controls gain focus and I want to prevent that.

I’ve invited @jules and @fabian and no response. Can we please get that premium support we’re paying for? Even an “I don’t know, seems like a bug” would be better than silence.

There are a whole heap of ways you can control focus ordering - have a look in the Component class. But maybe all you really want to do is to make the background parent component take focus, so that when you click outside the text editor, the background gets focused. Because if the parent can’t take focus and you click on it, the system will hunt around for something that does want focus, and your TextEditor looks like a great candidate.

…or actually, if clicking on the sliders is causing focus to go to the TextEditor, then clearly they’re also refusing focus. Maybe it’s them that you want to tweak so that they want it.

So each component basically has to tell the parent that it wants focus when clicked? Why isn’t that the default?

I think it would be a good feature to turn off this automatic focus hunting. What would be the fastest/easiest way to accomplish that?

There are lots of ways to do it, focus is a complicated subject. Have a look at Component::setWantsKeyboardFocus, setMouseClickGrabsKeyboardFocus, setFocusContainer, setExplicitFocusOrder, KeyboardFocusTraverser

Could I implement a KeyboardFocusTraverser that always returns the main component or a nullptr and nothing (or the main-component) would get focus?

Well yes, a KeyboardFocusTraverser can do whatever you want it to. Depending on exactly what you want to do though, there could be easier ways just by tweaking the settings of the other components.

What I want exactly: no focus changes ever. The TextEditor’s (no matter in which relationship they are to the current group etc.) should never receive keyboard focus unless the user actively clicks on them or my code sets the focus manually.

Fiddling with other functions sounds like a nightmare, as I have literally hundreds of controls etc. and I don’t want to add “setFocusContainer” and other related calls all over the place to wrangle the system under control.

If a single KeyboardFocusTraver can be implemented and set once as the default, that would be heaven.

The current behaviour makes sense for websites, or apps that use a lot of form with keyboard input, but for a standard audio-plugin with a hardware-like look, it’s completely disruptive as (seemingly) random TextEditors activate just because the user tweaks the volume, cutoff or something in the same group.