Slider value update not working after dragging #8327
Answered
by
FloVanGH
J0hannes101
asked this question in
Q&A
-
Bug DescriptionWhat is the bug?
Expected behavior:
What happened instead:
Steps to reproduce:
Reproducible Code (if applicable)ui.slint: import { VerticalBox, Slider, Button } from "std-widgets.slint";
export component AppWindow inherits Window {
in property <float> slider_value;
VerticalLayout {
Text {
text: "Slider Value: " + slider_value;
}
Slider {
minimum: 0;
maximum: 100;
value: slider_value;
}
}
} main.rs: use std::error::Error;
use std::time::Duration;
slint::include_modules!();
fn main() -> Result<(), Box<dyn Error>> {
let ui = AppWindow::new()?;
let mut time = 0;
let timer = slint::Timer::default();
timer.start(slint::TimerMode::Repeated, Duration::from_secs(1), {
let ui_clone = ui.as_weak();
move || {
let ui_clone = ui_clone.unwrap();
ui_clone.set_slider_value(time as f32);
println!("set position: {}", time);
time += 1;
}
}
);
ui.run()?;
Ok(())
} Environment Details
Product ImpactNo response |
Beta Was this translation helpful? Give feedback.
Answered by
FloVanGH
May 2, 2025
Replies: 1 comment 1 reply
-
Hi, I have converted this into a discussion because it's not a bug. To get it to work you need to use a two-way binding. I have adjusted your code so that it works: import { VerticalBox, Slider, Button } from "std-widgets.slint";
export component AppWindow inherits Window {
in property <float> slider_value <=> slider.value;
VerticalLayout {
Text {
text: "Slider Value: " + slider_value;
}
slider := Slider {
minimum: 0;
maximum: 100;
}
}
} use std::error::Error;
use std::time::Duration;
slint::include_modules!();
fn main() -> Result<(), Box<dyn Error>> {
let ui = AppWindow::new()?;
let timer = slint::Timer::default();
timer.start(slint::TimerMode::Repeated, Duration::from_secs(1), {
let ui_clone = ui.as_weak();
move || {
let ui_clone = ui_clone.unwrap();
ui_clone.set_slider_value(ui_clone.get_slider_value() + 1.);
println!("set position: {}", ui_clone.get_slider_value());
}
});
ui.run()?;
Ok(())
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
J0hannes101
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
and thank you for your report.
I have converted this into a discussion because it's not a bug. To get it to work you need to use a two-way binding.
I have adjusted your code so that it works: