如何立即更改OptionSelector中的索引(无动画)?

在我的应用程序中,我使用一个OptionSelector来从自行车站列表中进行选择。我还有一个地图组件,每个站点都有一个标记。
当我点击一个标记时,它也会将OptionSelector更改为相应站点的索引,因为这是良好的用户体验。
不好的用户体验是OptionSelector对这个索引变化的响应方式,它会像用户的手指一样以动画的形式自己滑动。换句话说,在用户点击地图标记并获得所需的所有信息之后很长时间,OptionSelector仍然在“旋转”到站点的索引位置。
这里有一个视频演示了这种行为: https://www.youtube.com/watch?v=jXKWlAmNYsw 我希望这个OptionSelector能立即改变其索引,而不需要动画。有没有办法做到这一点?
以下是我目前的做法。如果这种方法不正确,我非常乐意接受纠正。我使用一个WorkerScript(一个QML线程,或多或少)来进行API调用。当这个WorkerScript返回时,它会移动OptionSelector,如下所示:
WorkerScript {
    id: queryStationsWorker
    source: "../js/getstations.js"

    onMessage: {
        [...]

        // Move the OptionSelector to the corresponding station's index.
        stationSelector.selectedIndex = getLastStationIndex(lastStation.contents.stationName, stationsModel)

        /*
         * For the sake of clarity:
         *
         * getLastStationIndex() is a function which just returns an integer.
         * lastStation is a U1DB database used for state saving.
         * stationsModel is a model containing all of the stations.
         */
    }
}

任何帮助或见解都会受到赞赏 - 干杯!


能否请您提供一段足以重现问题的代码?当然,视频对于帮助理解也是有帮助的,但如果没有可重用的代码片段,我们很难给予您帮助(请参考http://sscce.org/)。 - Sylvain Pineau
嗨 Sylvain。抱歉耽擱了。這是一個供您測試的QML文件。只需創建一個新的Ubuntu Simple UI項目,然後將您的主要QML文件替換為此文件:http://pastebin.ubuntu.com/9534780/ - Aaron Hastings
1个回答

您可以在此处看到 OptionSelector qml 的副本这里,它在未展开时使用 UbuntuNumberAnimation。目前没有关闭它的选项,如果需要该功能,您将不得不修改上游并等待库的新版本一段时间。
不过,您可以自己制作一个打开的选择器小部件,删除动画部分,并确保为在您的代码中使用而重命名。我建议您采用这种方法。