V8.x imgbtn clear flag CHECKABLE not working?

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.


Setting checkable to false for an imgbtn in v7 work perfectly, but I have struggled to get the same behavior in v8 by clearing the CHECKABLE flag, ie:

lv_obj_clear_flag(nav_btn_left, LV_OBJ_FLAG_CHECKABLE);

Specifically I do not want the imgbtn to change colors (ie from grey to a lighter grey based on styling) after being pressed. I think this should be working and I am missing something simple.

What MCU/Processor/Board and compiler are you using?

teensy 4.1

What LVGL version are you using?


What do you want to achieve?

Clearing the CHECKABLE flag should prevent an imgbtn from changing based on styling. I can likely override the styling, but it would be cleaner to be able to use the flag.

What have you tried so far?

Clearing the CHECKABLE flag.

Code to reproduce

Not going to include the image code as it’s kinda large:

#define COLOR_SCR_TEXT lv_color_hex(0xe7e9ec)
#define COLOR_BTN_DIS lv_color_hex3(0x888)

lv_style_t imgbtn_style;
lv_style_set_img_recolor_opa(&imgbtn_style, LV_OPA_40);
lv_style_set_img_recolor(&imgbtn_style, COLOR_SCR_TEXT);

lv_obj_t *nav_btn_left = lv_imgbtn_create(NULL);
lv_obj_add_style(nav_btn_left, &imgbtn_style, 0);
lv_obj_set_style_img_recolor(nav_btn_left, COLOR_BTN_DIS, LV_PART_MAIN | LV_IMGBTN_STATE_DISABLED);
lv_obj_clear_flag(nav_btn_left, LV_OBJ_FLAG_CHECKABLE);

Screenshot and/or video

With my current grey color it is hard to capture the different colors with a pic.


CHECHKABLE means the object toggles between LV_STATE_DEFAULT and LV_STATE_CHECKED when clicked.

However there is an issue in this line:

lv_obj_set_style_img_recolor(nav_btn_left, COLOR_BTN_DIS, LV_PART_MAIN | LV_IMGBTN_STATE_DISABLED);

It should be

lv_obj_set_style_img_recolor(nav_btn_left, COLOR_BTN_DIS, LV_PART_MAIN | LV_STATE_DISABLED);

Or simple:

lv_obj_set_style_img_recolor(nav_btn_left, COLOR_BTN_DIS, LV_STATE_DISABLED);

Thanks @kisvegabor! Changing to use the LV_STATE_DISABLED enum fixed the issue.

Setting LV_IMGBTN_STATE_DISABLED was the same as setting LV_STATE_FOCUSED, which matches the behavior I was seeing.

1 Like

Good to hear it works now :slight_smile: