2017-03-28 13 views
-1

ListViewコンポーネントを使用していますが、currentIndexプロパティで問題があります。私はQml listViewミラーリングレイアウトの現在のインデックス

onCurrentIndexChanged: 

に何らかのアクションをしたいしかし、私が使用している場合

LayoutMirroring.enabled: true 

currentIndex

はもう更新されません。 onCurrentIndexChangedにはアクションはありません。また、currentIndexは常に0になります。 私も使用しようとしました
layoutDirection: Qt.RightToLeft しかし、問題は同じです(リストビューを移動したときには currentIndexの更新はありません)。

あなたは

snapMode: ListView.SnapToItem 

を使用する場合にもcurrentIndexするために

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); 
     } 
    } 

だから私の質問はです:私はLayoutMirroring.enabled: trueまたはlayoutDirection: Qt.RightToLeftを使用している場合、リストビューをスクロールしながらcurrentIndexが更新持って何をする必要がありますか。

+0

-1:**質問が欠落しています** *何が起こっている、あなたがしたくありません* - ? *私はあなたのコードを実行することができません問題を参照してください。*ミラーリングされた 'ListView'を試したとき、すべてが期待どおりに動作します。指定してください。 – derM

+0

投稿の最後に質問を更新しました。 – Kostek

答えて

0

私は解決策を得ました!

問題は、このラインのbeacuseた:回転ビューについて

preferredHighlightBegin: id_multiCouplingMeasurePopup.p_bViewRotated ? id_couplingControlView.width : id_couplingControlView.leftMargin 

Iは、リストビュー自体の幅と同じ幅preferredHighlightBeginを設定しました。そのためcurrentIndexは更新されませんでした。 listViewをミラーリングすることは何もしませんでした。

0

Minimal, Complete and Verifyable Exampleを提供していた場合は、問題の核となる可能性があります。あなたが想定さまさに、実行する必要があります:

  • ListViewが水平ください:項目にLayoutMirroring.enabled: true
  • スナップ:orientation: ListView.Horizontal
  • は、ミラーリングを有効に実際にsnapMode: ListView.SnapToItem < =だから、あなたの質問に答えるために

    オプションのように見える

  • currenItemを表示するように強制してください。highlightRangeMode: ListView.StrictlyEnforceRange

これは、MCVEは、次のようになりどのように期待どおりに動作することを証明している:

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) 
    } 
} 
関連する問題