Getting the height of a RichTextLabel after appending

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By stoff

Hi everybody! :slight_smile:

What is the best way to get the Height of a RichTextLabel, after appending a text?
I tried this so far:

extends RichTextLabel

func _ready():
    fit_content_height = true
    bbcode_enabled = true
    rect_min_size.x = 50
    append_bbcode("Lorem ipsum dolor sit amet, consetetur sadipscing...")
    #this prints: (0, 0, 40, 40) which is the default size of the label before appending any text
    #this prints: a seemingly random number? (scary...)
:bust_in_silhouette: Reply From: db0

I run into the same problem. This doesn’t seem to be happening.

What seems to work for me is:

func get_min_height() -> float:
	var theme : Theme = self.theme
	var label_font : Font
	if theme:
		label_font = theme.get_font("font", "RichTextLabel").duplicate()
		label_font = get("custom_fonts/normal_font").duplicate()

And then set the rect_min_size after changing the text

rect_min_size.y = get_min_height()

Relevant bug report: