Change button-font when hovered

Godot Version

4.2 Stable

Question

Hi! I want to change the font of a button when hovered. I have set my buttons up in a
VBoxContainer. I have no idea of how to do this, I have tried with themes and code, but there is apparently no one else that has tried this, because I could not find any good sources for how to do this. I don’t even know if this is posibble.

Have started by setting up a script that recognizes when the mouse is over the button?

But do you know how to change the properties of the button? Everything I’ve looked at is for godot 3.

Are you trying to change the font face or something else like size or color?

I want to change the button-font to italic (for that I have two separate fonts) when hovered.

Does this work?

1 Like

Thank you so much! :upside_down_face: This worked for me:

func _on_play_mouse_entered():
	var fv = FontVariation.new()
	fv.set_base_font(load("res://assets/fonts/Italic.otf"))
	
	$MarginContainer/VBoxContainer/Play.add_theme_font_override("font", fv)

func _on_play_mouse_exited():
	var fv = FontVariation.new()
	fv.set_base_font(load("res://assets/fonts/Regular.otf"))
	
	$MarginContainer/VBoxContainer/Play.add_theme_font_override("font", fv)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.