Qt Qml listView镜像布局当前索引
我正在使用ListView组件,在使用Qt Qml listView镜像布局当前索引,qt,listview,qml,mirroring,Qt,Listview,Qml,Mirroring,我正在使用ListView组件,在使用currentIndex属性时遇到问题。我想在这方面采取一些行动 onCurrentIndexChanged: 但是当我使用 LayoutMirroring.enabled: true currentIndex不再更新。当CurrentIndexchanged时,中没有任何操作,currentIndex始终等于0。 我还尝试使用 布局方向:Qt.right到left 但问题是相同的(当listView移动时,没有任何currentIndex更新) 我已经
currentIndex
属性时遇到问题。我想在这方面采取一些行动
onCurrentIndexChanged:
但是当我使用
LayoutMirroring.enabled: true
currentIndex
不再更新。当CurrentIndexchanged时,中没有任何操作,currentIndex始终等于0。
我还尝试使用
布局方向:Qt.right到left
但问题是相同的(当listView移动时,没有任何currentIndex
更新)
我已经阅读了ListView文档,其中有一些信息,如果您使用
snapMode: ListView.SnapToItem
您还需要添加
highlightRangeMode: ListView.StrictlyEnforceRange
为了确保正确更新当前索引。也许有类似的镜像布局
以下是全部代码:
ListView
{
id: id_couplingControlView
model: id_multiCouplingMeasurePopup.p_iCouplingsCount
orientation: ListView.Horizontal
snapMode: ListView.SnapToItem
highlightRangeMode: ListView.StrictlyEnforceRange //To update the currentIndex as the list is moved
preferredHighlightBegin: id_multiCouplingMeasurePopup.p_bViewRotated ? id_couplingControlView.width : id_couplingControlView.leftMargin
LayoutMirroring.enabled: id_multiCouplingMeasurePopup.p_bViewRotated
//layoutDirection: id_multiCouplingMeasurePopup.p_bViewRotated ? Qt.RightToLeft : Qt.LeftToRight
delegate: QmlSHMultiCouplingMeasureControl
{
id: id_CouplingMeasureControl
p_iIndex: index
Component.onCompleted:
{
InitializeCouplingControl ( id_CouplingMeasureControl )
}
}
//Need to to something here
onCurrentIndexChanged:
{
console.log ( "onCurrentIndexChanged:: " + id_couplingControlView.currentIndex )
id_multiCouplingMeasurePopup.UpdateMiniTrainCouplingList( id_couplingControlView.currentIndex );
}
}
所以我的问题是:当使用layoutmrirroring.enabled:true
或layoutDirection:Qt.right toleft
时,我需要做什么才能在滚动列表视图时更新currentIndex
好的,我找到了解决方案
问题是因为这一行:
preferredHighlightBegin: id_multiCouplingMeasurePopup.p_bViewRotated ? id_couplingControlView.width : id_couplingControlView.leftMargin
对于旋转视图,我将首选HighlightBegin
的宽度设置为listView本身的宽度。这就是为什么currentIndex没有更新。镜像listView与此无关 如果您提供了一个解决方案,我们可能会深入到您问题的核心
所以要回答你的问题:你需要做的,就是你假设的:
- 使
ListView
水平:方向:ListView.horizontal
- 启用镜像:
layoutmrirroring.enabled:true
- 捕捉到项目:
snapMode:ListView.SnapToItem
-1:缺少问题:发生了什么您不想发生的事情?-否:我无法运行您的代码,以查看任何问题。当我尝试镜像的ListView
时,一切正常。请具体说明。我已经更新了帖子底部的问题。
ListView {
id: lv
model: 100
LayoutMirroring.enabled: true
orientation: ListView.Horizontal
width: 500
height: 100
spacing: 5
snapMode: ListView.SnapToItem
highlightRangeMode: ListView.StrictlyEnforceRange
onCurrentIndexChanged: console.log('Current Index changed to', currentIndex)
delegate: Rectangle {
width: 100
height: 100
color: lv.currentItem === this ? Qt.rgba(1, 0, 0, 1) : Qt.rgba(0, 0, 1, index / 200 + 0.5)
}
}