2017-12-08 4 views
0

私は、FlickableでbackGroundListとトップのgridviewを持っています。gridview contentを処理する方法親からのYの位置QMLのFlickable

グリッドビューのコンテンツYを親から持ちたいFlickable、コンテンツの高さとしてグリッドビューの高さを割り当てるときに動作していますが、メモリの問題が原因で以前にアイテムを作成したくありません。

コード:予想通り

Flickable { 
      id: mainFlickable 
      width: 1920 
      height: 1080 
      contentHeight: gridView.contentHeight + 660 + 140 // topmargin + bottom margin 

      ListView { 
       id:backGroundList 
       width: 1920 
       height: 1080 
       y: mainFlickable.contentY 
       orientation: ListView.Horizontal 

       MouseArea { 
        id: myMA12 
        anchors.fill: parent 
        hoverEnabled: true 
       } 
      } 

      GridView { 
       id: gridView 
       objectName: "gridView" 

       width: 1920 
       height: 1080 



       cellWidth: 372 
       cellHeight: 290 

       interactive: false 
       y: { 
        if (mainFlickable.contentY > 660) 
         return 660 + (mainFlickable.contentY - 660) 
        else 
         return 660 
       } 

       contentY: { 
        if (mainFlickable.contentY > 660){ 
         return (mainFlickable.contentY - 660) 
        } 
        else { 
         return 0 
        } 
       } 

       delegate: Rectangle { 
        width: 352 
        height: 270 
        color: "blue" 
        opacity: 0.5 

        Text { 
         text: index 
         anchors.centerIn: parent 
        } 
       } 
       model:100 
       anchors { 
        left: parent.left 
        leftMargin: 30 
        right: parent.right 
        rightMargin: 30 
       } 
      } 
} 

そのが働いていません。 Qt5.9.0

は、いくつかのいずれかがこの上で私を助けることができます:私はYを更新すると値ContentYは自動的に

制約をゼロに更新しています。

+1

あなたのUIをどのように見せるかについての素早いワイヤフレームを提供できますか?私たちにあなたのニーズのより高いレベルの見解を与える。 2つのFlickablesを1つに入れ子にして間違っているように感じる( 'ListView'と' GridView'は両方とも 'Flickable'から継承しています) – GrecKo

答えて

0

私があなたのことを正しく理解していれば、もう一方のオントップの2つを持ちたいと思っています。それらのうちの1つが最後までフリックしたとき、あなたはそのウィンドウの外にViewをフリックさせたいと思っています。もう1つはApprearingし、これを使ってフリックします。

私の意見では、これは1つのFlickableが他の2つを入れ子にすることできれいに受け入れられません。

兄弟であるFlickableを使用すると簡単に達成できます。私のコード例では、2つのFlickablesを使用しています。 1つはcontentYのプロパティの制御用であり、もう1つは2つの間のスクロールを担当するものです。View LatterはItemを使用するだけで、簡単かつ効率的に解決できます。

Window { 
    id: rootWin 
    width: 800; height: 600; visible: true 

    Flickable { 
     id: flck 
     anchors.fill: parent 
     contentHeight: lv1.height + lv2.height 
     interactive: false 
     contentY: Math.min(Math.max(0, mainFlick.contentY - lv1.contentHeight + lv1.height), contentHeight - height) 

     ListView { 
      id: lv1 
      height: rootWin.height 
      width: 100 
      model: 90 
      delegate: Rectangle { 
       border.width: 1 
       width: 100 
       height: 50 
       Text { 
        anchors.centerIn: parent 
        text: index 
       } 
      } 
      interactive: false 
      contentY: Math.min(mainFlick.contentY, contentHeight - height) 
      onContentYChanged: console.log(contentY, contentHeight, height) 
     } 
     ListView { 
      id: lv2 
      height: rootWin.height 
      anchors.top: lv1.bottom 
      width: 100 
      model: 90 
      delegate: Rectangle { 
       border.width: 1 
       width: 100 
       height: 50 
       Text { 
        anchors.centerIn: parent 
        text: index 
       } 
      } 
      interactive: false 
      contentY: Math.min(Math.max(0, mainFlick.contentY - lv1.contentHeight), contentHeight - height) 
     } 
    } 
    Flickable { 
     id: mainFlick 
     anchors.fill: parent 
     contentHeight: lv1.contentHeight + lv2.contentHeight 
    } 
} 
関連する問題