How to make a checkable button react on press


How to make a checkable button react on press.

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


What LVGL version are you using?


What do you want to achieve?

I want to make a checkable button chage checked state on press (not on release).

What have you tried so far?

Tried many things. Added of course the flag LV_OBJ_FLAG_CHECKABLE.
Same question, less important for me, to create the same behaviour for the tabView widget.

Setting or clearing the flag this way:
lv_obj_t *tabViewBtnMatrix = lv_tabview_get_tab_btns(tabSet);
lv_btnmatrix_set_btn_ctrl_all(tabViewBtnMatrix, LV_BTNMATRIX_CTRL_CLICK_TRIG);
does not work.

Thnx in advance for any ideas.

you require CLICKABLE and handle events for it

Thank you for a response.
I know these flags. I use the LV_OBJ_FLAG_CHECKABLE to make a button to be switched on and off by two separate user actions.
But in this case, the lvgl button reacts not like a physical button. Those usually become ‘checked’ on the first press and not on the first release.
I want the button to send the event ‘LV_EVENT_VALUE_CHANGED’ on a press action of the user. Would be great if that could be achieved.

I tried the clicked event. The ckicked event is send at button release. (The touchscreen release.)

Using the event LV_EVENT_PRESSED and do all the ‘checked/not checked’ logic myself could make it work.

Can somebody confirm the flag LV_OBJ_FLAG_CHECKABLE does not support an object check-change on the press-event?

I test it in SQ and it work

A pity I don’t know SQ.
What I assume is that SQ implements an event handler on the press event. That will work indeed. But, it is not clear if the toggling needs to be done by the lvgl object or the toggling needs to be done in the user specific event handler.
For me the solution, for now, is to toggle in the user event handler and avoid lvgl flipping the checked state and do some paintwork by not adding the behavior flag ‘LV_OBJ_FLAG_CHECKABLE’.