0 votes

Hi everybody! :)

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...")

    print(get_rect())
    #this prints: (0, 0, 40, 40) which is the default size of the label before appending any text

    print(get_content_height())
    #this prints: a seemingly random number? (scary...)
Godot version v3.3
in Engine by (17 points)

1 Answer

0 votes

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()
    else:
        label_font = get("custom_fonts/normal_font").duplicate()
    return(label_font.get_height())

And then set the rectminsize after changing the text

rect_min_size.y = get_min_height()

Relevant bug report: https://github.com/godotengine/godot/issues/18260

by (85 points)
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 webmaster@godotengine.org with your username.