+1 vote

Hey.
I have a program that dynamically creates a chart. How can I make it so that when I press / hover, the text (value of a given point) is shown above a given point?

This is what I want to do about.

I already have a function responsible for clicking on a point, but so far it only displays text in the console.

func app_in_arr():
    but_text.append(add_btn())
    but_text[points_arr.size()-1].connect("pressed", self, "btn_press",[but_text[points_arr.size()-1]])

func btn_press(_button):
    print("correct value")

func add_btn():
    var new_button = TextureButton.new(); 
    add_child(new_button); 
    new_button.name = str(points_arr.size())
    new_button.rect_size = Vector2(20,20); 
    new_button.rect_global_position = Vector2(x+50.36,(-y/now_del)+440.41);
    new_button.texture_normal = load("res://sprites/empty_texture.png")
    new_button.pause_mode = Node.PAUSE_MODE_PROCESS
    return new_button

I need, instead of the print, the value to be displayed as in the screenshot above.

in Engine by (21 points)

Could you dynamically place a Label at each of those points, and when the user moves their cursor over the point, the Label is shown? Failing that, maybe the points have tooltips? Control nodes have the hint_tooltip property, so maybe you could use that?

Thank. I did not find a way to connect hint_tooltip, so I decided to just create a label in the same way as buttons. The only thing I don’t understand is how to read the hover over the button? Only pressed works.

1 Answer

+2 votes
Best answer

I did not find a way to connect hint_tooltip

You don't need to connect anything:

func btn_press(_button):
    hint_tooltip = "correct value"

how to read the hover over the button?

Connect to the mouse_entered|exited-signals:

func app_in_arr():
    but_text.append(add_btn())
    # TODO: add the label node?
    but_text[points_arr.size()-1].connect("mouse_entered", self, "_on_btn_mouse_entered", [but_text[points_arr.size()-1]])
    but_text[points_arr.size()-1].connect("mouse_exited", self, "_on_btn_mouse_exited", [but_text[points_arr.size()-1]])

func _on_btn_mouse_entered():
    get_node("<PathToYourLabel>").show()

func _on_btn_mouse_exited():
    get_node("<PathToYourLabel>").hide()
by (10,610 points)
selected by
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 Frequently asked questions and 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 [email protected] with your username.