在QML TestCase中,我试图设置Flickable内部包含的ListView的自动滚动(以添加可以轻拂到视图中的自定义页脚,仅ListView { footer: Component {} }
不会发生这种情况]
但是,mouseDrag
似乎只是单击正确的坐标,而没有将其拖动到任何方向。这是一个简化的版本,它尽可能接近真实版本:
Implementation.qml
import QtQuick 2.5
FocusScope {
width: 1920
height: 1080
Flickable {
objectName: 'flickableList'
boundsBehavior: Flickable.StopAtBounds
clip: true
width: parent.width
height: 240
contentHeight: 500
ListView {
interactive: false
height: parent.height
width: parent.width
model: ['example1', 'example2', 'example3', 'example4', 'example5']
delegate: Item {
width: 300
height: 100
Text {
text: modelData
}
}
}
}
Item {
id: footer
height: 100
width: parent.width
}
}
TheTest.qml
// The relevant part
var theList = findChild(getView(), 'flickableList')
var startY = 220
var endY = 20
mouseDrag(theList, 100, startY, 100, endY, Qt.LeftButton, Qt.NoModifier, 100)
因此,当我查看UI测试运行程序时,我可以清楚地看到它单击正确的委托(它在实际实现中具有重点突出显示),即。第三项“ example3”,从Y 200开始,到Y 300结束。但是拖动事件永远不会发生。屏幕上没有任何动静,compare(theList.contentY, 200)
表示它仍在位置0
。我希望它位于200
,因为鼠标应该从位置mouseDrag
移到220
,即20
。向下滚动列表200
。并且220
也在可见高度(240
)之内。
请确定,我也反转了Y值,但也没有移动:
var theList = findChild(getView(), 'flickableList')
var startY = 20
var endY = 220
mouseDrag(theList, 100, startY, 100, endY, Qt.LeftButton, Qt.NoModifier, 100)
此外,当清楚地单击第三个项目(突出显示)时,传递的项目theList
(=可滑动)应该是有效的。
编辑:哦,确实可以滚动列表,但是一直到列表底部(即使增量只有30个像素,实际实现中也向下388像素):
mousePress(theList, startX, startY)
mouseMove(theList, endX, endY)
mouseRelease(theList, endX, endY)
所以问题是:
mouseDrag
仅适用于特定类型的组件(即,对Flickable
不起作用吗?),还是缺少某些内容?我如何才能向下滚动列表?谢谢!
您的标签说您正在使用Qt 5.5-如果可能的话,我建议您尝试使用Qt 5.14,因为有一个修复程序可能会有所帮助:
mouseDrag():确保对所有拖动进行中间移动
我认为mouseDrag仅适用于鼠标区域。您可以用它包装每个对象。但是最后,您需要在委托内部使用鼠标区域并将其拖放。