How to disable a slider?

Is it possible to disable a slider? Buttons have an Inactive state, but I don’t see anything similar for sliders.

I thought about setting the minimum to the maximum so it has nowhere to move, but that is giving me a Floating point exception (divide-by-zero) which makes sense as I’m sure it’s dividing by the delta(min, max) to get a percentage.

1 Like

Isnt a disabled slider a bar?

lv_obj_t * bar1 = lv_bar_create(lv_scr_act(), NULL);
lv_obj_set_size(bar1, 400, 60);
lv_obj_align(bar1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_bar_set_anim_time(bar1, 200);

I suppose that’s one way to do it, but it lacks the knob that makes it look like a slider. Preferably I’d have a grayed out slider that still looks like the normal, active object.

You should call lv_obj_set_click(slider, false) to make in non-clickable.

1 Like

That’s too simple a solution… :slight_smile: Thank you!

1 Like

No solution for LVGL 8?
Documentation for LVGL 7 is great, but for 8 it’s really bad.

how can be implemented something that instead interact just with clicks and disable drag?
If i want to implement a slider that has steps instead of each value inside a range for example, how i can avoid to drag the slider and just have a “click” interaction on the bar?!
Thanks in advance! :smiley:

What if you set the range to something smaller, like [0..10]?

Ciao Gabor, the range is from 60 to 180 in my case, with steps of 30.
Basiacally is a slider that help the user to select a time from 60 seconds to 180, with steps of 30 seconds. :slight_smile:

You can set the range to 0…4, and in the event just value * 30 + 60.

ciao Gabor, yep this exactly is the approach i’ve used

if(act_cb == gui.page.settings.multiRinseTimeSlider) {
    if(code == LV_EVENT_RELEASED) {
        current_value = gui.page.settings.settingsParams.multiRinseTime;
        new_value = lv_slider_get_value(act_cb);

        if(new_value > current_value) {
            new_value = current_value + 30;
        } else if(new_value < current_value) {
            new_value = current_value - 30;
        }

        // Ensure new_value is within valid bounds (assuming 60 to 180 as mentioned)
        if(new_value < 60) new_value = 60;
        if(new_value > 180) new_value = 180;

        lv_slider_set_value(act_cb, new_value, LV_ANIM_OFF);  // Update the slider value to the nearest 30
        lv_label_set_text_fmt((lv_obj_t*)lv_event_get_user_data(e), "%ds", new_value);
        LV_LOG_USER("Multi rinse cycle time (s): %d", new_value);
        gui.page.settings.settingsParams.multiRinseTime = new_value;
        qSysAction(SAVE_PROCESS_CONFIG);
    }
}

Thanks @kisvegabor :smiley:

1 Like