I am testing with making custom tooltips. I can make a RichTextLabel but the contents does not stay open long enough to copy or click on from it. I am looking for a way to move mouse over the tooltip and copy/click and then hover away to close. This is actually how Godot Editor does it.
Here is my code: Create a any control, e.g. a button, add some tooltip text to it and then add the code as script to it. When you hover over button tooltip show but no way to move mouse over it.
Any ideas?
extends RichTextLabel
func _make_custom_tooltip(for_text):
var label := RichTextLabel.new()
label.autowrap_mode=TextServer.AUTOWRAP_OFF
label.bbcode_enabled=true
label.fit_content=true
label.clip_contents=false
label.text = "Example: The word [color=lightblue][url=https://www.bbcode.org]BBCode[/url][/color] is clickable.
\nThe word [color=red]guide[/color] is colored blue."
return label
Example Godot hovering over the Tooltip Text in the inspector: Remains open when moving mouse over it.
this is true, most importantly make it inside its own CanvasLayer layer, typically higher layer than the basic layer 0. put a Control node that has Full Rect Preset to block input or simply a blank StyleBoxEmpty Button to close the tooltip on clicking outside the panel info
Here is a rough version of the code that works now. Needs lots of tweaking. The key to it making a separate node, adding a timer and then hiding it appropriately. Now I need to make it into a generic class for easier use.
If you mouse over a node with a tooltip, it starts a 4 sec timer and shows the custom tooltip.
It will close in 4 seconds if you dont mouse to the tooltip.
If you mouse enter the tooltip, the timer is disabled and if you mouse out it closes it.
extends RichTextLabel
var label:RichTextLabel
func _make_custom_tooltip(for_text):
label = RichTextLabel.new()
label.name="Tooltip"
label.autowrap_mode=TextServer.AUTOWRAP_OFF
label.bbcode_enabled=true
label.fit_content=true
label.clip_contents=false
label.text = "Example: The word [color=lightblue][url=https://www.bbcode.org]BBCode[/url][/color] is clickable.
\nThe word [color=red]guide[/color] is colored blue."
label.position=position+Vector2(20,20)
#get_global_mouse_position()-Vector2(-50,50)
var sb:=StyleBoxFlat.new()
sb.set_border_width_all(2)
sb.border_color=Color.GREEN
sb.bg_color=Color.BLACK
label.add_theme_stylebox_override("normal",sb)
label.connect("mouse_entered",_mouse_in)
label.connect("mouse_exited",_mouse_out)
var timer := Timer.new()
timer.name="TooltipTimeout"
label.add_child(timer)
timer.wait_time = 2.0
timer.one_shot = true
timer.connect("timeout", _mouse_out)
$"..".add_child(label)
label.visible=true
label.show()
timer.start()
var dummy:=Label.new()
dummy.tooltip_text=''
return dummy
func _mouse_in():
var t:Timer=label.get_node_or_null("TooltipTimeout")
if t != null:
t.stop()
print("mouse in")
func _mouse_out():
print("mouse out")
if label != null:
label.queue_free()