Make control nodes lose focus when clicking in any part of the screen
Asked Answered
M

6

0

How do you make it so that when you click away from a control it loses focus? so for example i have my button selected, but I want it so that whenever you click in any other part of the screen it loses focus.

Monnet answered 23/7, 2022 at 15:56 Comment(0)
M
0

Thermodynamics it works for gaining focus, but to for releasing it. If i click on an empty part of the screen focus isn't lost

Monnet answered 31/7, 2022 at 15:9 Comment(0)
T
0

Maybe only Controls respond to clicking? Does the screen have a background that's a Control, like a ColorRect or TextureRect?

Thermodynamics answered 31/7, 2022 at 17:56 Comment(0)
A
2

Monnet
Create another Control node, which I will call "Background Control" for simplicity. On top of this node, add the Control node you're interested in; let's call "Main Control". Write code so that when the "Background Control" is clicked, it gains focus. This way, the focus is switched from "Main Control" to "Background Control". Tree structure could be this:
-Parent
--------Background Control
------- Main Control

OR this:
-Parent
--------Background Control
---------------Main Control

Attire answered 1/8, 2022 at 14:31 Comment(0)
H
1

Attire Wow! Super good way of fixing this! Though there is a problem which is that when you focus on the background Control, it becomes outlined. To fix this I just set "Control > Theme Overrides > Styles > Focus" to a new StyleBoxEmpty. Leaving this here for anyone that this might help.

Honebein answered 7/8, 2023 at 22:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.