Skip to content

Conversation

@6he
Copy link
Contributor

@6he 6he commented Nov 3, 2025

This is a follow up to PR #9696.

As suggested a struct property is used to save the reference values.
This also fixes the scrolling bug for the Qt style (Fixes #9208).

@6he
Copy link
Contributor Author

6he commented Nov 3, 2025

I tried to write a test as suggested in #9696, but I could not trigger the bug in the test.
In the test the ListView items are only updated after the PointerReleased event is send (see below).
Is there another way to trigger an update of the ListView items without releasing the mousebutton?

import { ListView } from "std-widgets.slint";

export component TestCase inherits Window {
    width: 100px;
    height: 100px;

    property<[length]> item-heights: [
         50px,
        150px,
        250px,
        350px,
        450px,
    ];

    list := ListView {
        width: parent.width;
        height: parent.height;

        mouse-drag-pan-enabled: true;
        vertical-scrollbar-policy: always-on;

        for height in item-heights: Rectangle {
            height: height;
        }
    }

    out property<length> viewport-height <=> list.viewport-height;
    out property<length> viewport-y <=> list.viewport-y;
}

/*

``````rust
use slint::{LogicalPosition, platform::WindowEvent};

let instance = TestCase::new().unwrap();

let button = slint::platform::PointerEventButton::Left;
let position = LogicalPosition::new(50.0, 50.0);

// move mouse to trigger instantiation of ListView items
instance.window().dispatch_event(WindowEvent::PointerMoved{ position });

println!("----> viewport-height: {}", instance.get_viewport_height());
println!("----> viewport-y: {}", instance.get_viewport_y());

// Scroll vertically by dragging the ListView
let position = LogicalPosition::new(50.0, 70.0);
instance.window().dispatch_event(WindowEvent::PointerMoved{ position });
instance.window().dispatch_event(WindowEvent::PointerPressed{ position, button });
let position = LogicalPosition::new(50.0, 19.0);
instance.window().dispatch_event(WindowEvent::PointerMoved{ position });

// the first item should be discarded at this point because it is no longer visible,
// but the items (and the estimated viewport-height) are only updated when the mousebutton is released.

instance.window().dispatch_event(WindowEvent::PointerReleased{ position, button });

println!("----> viewport-height 2: {}", instance.get_viewport_height());
println!("----> viewport-y 2: {}", instance.get_viewport_y());

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow up.

Comment on lines 86 to 89
self.saved-values.pressed-value = -root.value;
self.saved-values.maximum = root.maximum;
self.saved-values.x = self.mouse-x;
self.saved-values.y = self.mouse-y;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of one single assignment rather than 4 would be slightly more efficient:
self.saved-values = { pressed-value: -root.value, maximum: ..... }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adjusted the first commit.

@6he 6he force-pushed the listview-scroll-fix-followup branch from a6ab84e to d9bbc21 Compare November 4, 2025 13:50
@ogoffart ogoffart merged commit 4ea3eab into slint-ui:master Nov 4, 2025
45 checks passed
@ogoffart
Copy link
Member

ogoffart commented Nov 4, 2025

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ListView scrolling with scrollbar thumb jumps around

2 participants