LV_PART_INDICATOR dont work to change the font of indicator checkbox

What do you want to achieve?

I want to create a checkbox where the checkbox indicator uses my font (BainsleyBold)

What have you tried so far?

I’ve already tested to confirm that I correctly converted the font including the U+2713 “✓” symbol. I tried using:

lv_checkbox_set_text(first_check_box, “✓”);
lv_obj_set_style_text_font(first_check_box, &BainsleyBold, LV_PART_MAIN);
lv_obj_set_style_text_font(first_check_box, &BainsleyBold, LV_PART_INDICATOR | LV_STATE_CHECKED);

This correctly displays the “✓” when using the text, but when I try to apply the custom font to the checkbox indicator itself, it shows a rectangle with a white border, as if the character cannot be found in the font.

Code to reproduce

lv_obj_t *first_check_box = lv_checkbox_create(first_control_card);
  lv_checkbox_set_text(first_check_box, "✓");
  lv_obj_set_size(first_check_box, 97, 97);
  
  lv_obj_set_style_text_font(first_check_box, &BainsleyBold, LV_PART_MAIN);
  lv_obj_set_style_text_font(first_check_box, &BainsleyBold, LV_PART_INDICATOR | LV_STATE_CHECKED);

  lv_coord_t box_size = 97;
  lv_coord_t font_h = lv_font_get_line_height(&BainsleyBold);
  lv_coord_t pad = (box_size - font_h) / 2;

  lv_obj_set_style_pad_all(first_check_box, pad, LV_PART_INDICATOR);
  lv_obj_update_layout(first_check_box);

Screenshot and/or video

image_forum

Environment

  • LVGL version: See v9.2.2

The “checked” part, is defined as an image…

You need to for example:

lv_obj_set_style_bg_image_src(objects.text_check_box, LV_SYMBOL_USB, LV_PART_INDICATOR | LV_STATE_CHECKED);

It will change the symbol to:
image

In Your case, this should work (you need to apply the font in the same way):

#define LV_MY_SYMBOL_CHECKBOX        "\xE2\x9C\x93" /* 0x2713*/

  lv_obj_set_style_bg_image_src(objects.text_check_box, LV_MY_SYMBOL_CHECKBOX, LV_PART_INDICATOR | LV_STATE_CHECKED);
1 Like

It worked, thanks for the answer friend

1 Like