Using "lv_slider_set_value" function did not make callback function runs

Description

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

What do you experience?

Give a detailed description. “It doesn’t work” is not enough information for us to diagnose the issue.
I am not sure if this is a bug or it is something must be implemented.
I use “lv_slider_set_value” function to change slider value and using a label in slider’s callback to update label based on value of slider
if I change value of slider by touch it is working but when I change slider value by function label is not refreshing

What do you expect?

slider callback and events must be called even if I changed Slider value by “lv_slider_set_value” function

Code to reproduce

Use the ```c and ``` tags to format your code:


void slider_event_handler1(lv_obj_t *obj, lv_event_t event)
{
	if (event == LV_EVENT_VALUE_CHANGED)
	{
		sprintf(val, "%d", lv_slider_get_value(obj) * 500);
		lv_label_set_text(value1, val);
	}
}


void gui_slider_create1(lv_obj_t *parent, lv_event_cb_t cb)
{
	slider1 = lv_slider_create(parent, NULL);
	lv_slider_set_range(slider1, 0, 6);
	lv_obj_set_pos(slider1, 50, 0);

	lv_slider_set_style(slider1, LV_SLIDER_STYLE_BG, &style_bg);
	lv_slider_set_style(slider1, LV_SLIDER_STYLE_INDIC, &style_indic);
	lv_slider_set_style(slider1, LV_SLIDER_STYLE_KNOB, &style_knob);
	lv_obj_set_event_cb(slider1, cb);
	lv_obj_set_width(slider1, 90);

	/*Create additoinal objects (like labels) and save them in `gui_slider_t`*/

	name1 = lv_label_create(parent, NULL);
	lv_label_set_long_mode(name1, LV_LABEL_LONG_BREAK); /*Break the long lines*/
	lv_label_set_recolor(name1, true);					/*Enable re-coloring by commands in the text*/
	lv_obj_set_pos(name1, 10, 12);
	lv_obj_set_width(name1, 120);
	lv_label_set_text(name1, "S1");

	// value label
	value1 = lv_label_create(parent, NULL);
	lv_label_set_long_mode(value1, LV_LABEL_LONG_BREAK); /*Break the long lines*/
	lv_label_set_recolor(value1, true);					 /*Enable re-coloring by commands in the text*/
	lv_obj_set_pos(value1, 160, 12);					 /*Center aligned lines*/
	lv_label_set_text(value1, "0");
	lv_obj_set_width(value1, 60);
}

int main(){

 style_bg.body.main_color = LV_COLOR_BLACK;
    	style_bg.body.grad_color = LV_COLOR_GRAY;
    	style_bg.body.radius = LV_RADIUS_CIRCLE;
    	style_bg.body.border.color = LV_COLOR_WHITE;

    	lv_style_copy(&style_indic, &lv_style_pretty_color);
    	style_indic.body.radius = LV_RADIUS_CIRCLE;
    	style_indic.body.shadow.width = 8;
    	style_indic.body.shadow.color = style_indic.body.main_color;
    	style_indic.body.padding.left = 3;
    	style_indic.body.padding.right = 3;
    	style_indic.body.padding.top = 3;
    	style_indic.body.padding.bottom = 3;

    	lv_style_copy(&style_knob, &lv_style_pretty);
    	style_knob.body.radius = LV_RADIUS_CIRCLE;
    	style_knob.body.opa = LV_OPA_70;
    	style_knob.body.padding.top = 10;
    	style_knob.body.padding.bottom = 10;
    gui_slider_create1(lv_scr_act(), slider_event_handler1);
    lv_slider_set_value(slider1,2,false);
....

}

Screenshot and/or video

Based on how other GUIs work, I will assume (unless @kisvegabor says otherwise) that this is intended behavior. If you manually update the value with an API, the event handler will not be called. Event handlers are called when the user changes the value.

is there any way to send event manually ?

It’s explained in the event documentation.

1 Like

thanks,It worked
lv_event_send(slider1, LV_EVENT_VALUE_CHANGED, NULL);

Exactly, so that’s intentional.