Can several buttons under a parent object be mutually exclusive?All buttons have the LV_OBJ_FLAG_CHECKABLE(when Press to change the background color to red, then press again to change the background color to the default color),How can I make one button in the LV_STATE_CHECKED state(red) and all other buttons become default(blue)?
QT has an “exclusive” property, a group of buttons in a parent control, set this property to true, these buttons will be mutually exclusive
The translation of the Google page seems inaccurate, and I’m not sure my understanding gets it across. I was thinking of a set of buttons under the parent object, and when one of them is pressed, the others are released
Looking forward to your response
Hi @Sang19970619 ,
Here is a code snippet I posted for another question here :
static void event_handler(lv_event_t * e) {
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if(code == LV_EVENT_PRESSED) {
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
if( lv_btnmatrix_has_btn_ctrl( obj, id, LV_BTNMATRIX_CTRL_CHECKED ) ) {
lv_btnmatrix_clear_btn_ctrl(obj, id, LV_BTNMATRIX_CTRL_CHECKED);
} else {
lv_btnmatrix_clear_btn_ctrl_all(obj, LV_BTNMATRIX_CTRL_CHECKED);
lv_btnmatrix_set_btn_ctrl(obj, id, LV_BTNMATRIX_CTRL_CHECKED);
}
}
}
static const char * btnm_map[] = {"1", "2", "3", "4", "5", "" };
void button_demo(void) {
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
lv_btnmatrix_set_map(btnm1, btnm_map);
lv_obj_align(btnm1, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(btnm1, event_handler, LV_EVENT_PRESSED, NULL);
}
I think this can be adapted to your requirements.
I hope that helps.
Kind Regards,
Pete