0 votes

I've been trying to find a way to implement a mouse enter/leave event for a list of Tree Items within a Tree parent (select mode set to row), with no luck so far. From what I can see the only enter/leave signal resides in the parent control (using its rect).

Does anyone know how I can resolve this issue? Or at the very least implement a custom event?

Thanks

Godot version latest
in Engine by (21 points)

2 Answers

0 votes
Best answer

Ok so I figured out how to achieve this effect (Mono C#).

Attach a script to your tree

Add a TreeItem var.

TreeItem hover

Declare a trigger for both mouseentered and mouseexited:

    Connect("mouse_entered",this,"Mouse_Entered");
    Connect("mouse_exited",this,"Mouse_Exited");

If other unrelated code exists in the _process function add a bool and swap its state in these triggers. In my case the process only has one purpose so I enabled/disable the function.

private void Mouse_Entered(){
    SetProcess(true);
}

private void Mouse_Exited(){
    SetProcess(false);
}

Then add this to process: (use a bool check if not needed).

 public override void _Process(float delta)
{
    TreeItem temp = GetItemAtPosition(GetLocalMousePosition());
    if (temp != hover){
        for (int i = 0; i < Columns; i++)
        {
            if (hover != null) hover.ClearCustomColor(i);
            if (temp != null) temp.SetCustomColor(i, Colors.Red); 
        }
        hover = temp;
    }        
}
by (21 points)
+1 vote

If you look at the docs for TreeItem, you can see that it only inherits from Object, so it doesn't have any mouse signals. You'll either have to try using the Tree functions or making your own tree with other controls.

by (7,190 points)

Ah i see. I was hoping that wasn't the case. Thanks for the info

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.