2016-09-07 10 views
2

ヘッダーデリゲートを有効にしたListViewがあります。私は、 "OverlayHeader"に設定されたヘッダ位置付けプロパティを持っています。ヘッダーは、要素をスクロールするときにそのまま残ります。ただし、要素はヘッダーと重複します。これを防ぐ方法はありますか?QML ListView、スクロール時に、リスト要素をヘッダーと重ならないようにする方法。

Example of list elements overlapping the header.

import QtQuick 2.5 

Rectangle { 
    width: 360; height: 600 

    ListView { 

    width: 350; height: 200 
    anchors.centerIn: parent 
    id: myList 
    model: myModel 
    highlight: highlightBar 
    clip: true 

    snapMode: ListView.SnapToItem 

    headerPositioning: ListView.OverlayHeader 

    header: Rectangle { 
     id: headerItem 
     width: myList.width 
     height:50 

     color: "blue" 

     Text { 
     text: "HEADER" 
     color: "red" 
     } 
    } 

    delegate: Item { 
     id: delegateItem 
     width: 400; height: 20 
     clip: true 
     Text { text: name 
     } 

     MouseArea { 
     id: mArea 
     anchors.fill: parent 
     onClicked: { myList.currentIndex = index; } 
     } 
    } 

    } 

    Component { 
    id: highlightBar 
    Rectangle { 
     width: parent.width; height: 20 
     color: "#FFFF88" 
    } 
    } 

    ListModel { 
     id: myModel 
    } 

    /* Fill the model with default values on startup */ 
    Component.onCompleted: { 
     for(var i = 0; i < 100; i++) { 
      myModel.append({ name: "Big Animal : " + i}); 
     } 
    } 
} 

答えて

2

header's default z value is 1、あなたはそれが代表団を介しだことを確認するために、より高い値に設定することができますので:

import QtQuick 2.5 

Rectangle { 
    width: 360 
    height: 600 

    ListView { 

     width: 350 
     height: 200 
     anchors.centerIn: parent 
     id: myList 
     model: myModel 
     highlight: highlightBar 
     clip: true 

     snapMode: ListView.SnapToItem 

     headerPositioning: ListView.OverlayHeader 

     header: Rectangle { 
      id: headerItem 
      width: myList.width 
      height: 50 
      z: 2 

      color: "blue" 

      Text { 
       text: "HEADER" 
       color: "red" 
      } 
     } 

     delegate: Item { 
      id: delegateItem 
      width: 400 
      height: 20 
      Text { 
       text: name 
      } 

      MouseArea { 
       id: mArea 
       anchors.fill: parent 
       onClicked: { 
        myList.currentIndex = index 
       } 
      } 
     } 
    } 

    Component { 
     id: highlightBar 
     Rectangle { 
      width: parent.width 
      height: 20 
      color: "#FFFF88" 
     } 
    } 

    ListModel { 
     id: myModel 
    } 

    /* Fill the model with default values on startup */ 
    Component.onCompleted: { 
     for (var i = 0; i < 100; i++) { 
      myModel.append({ 
       name: "Big Animal : " + i 
      }) 
     } 
    } 
} 

clipping view delegates is bad for performanceこと。

+1

ありがとうございます。私はこれに頭を叩いている。私はすべてを試していた。私はどこにでもクリッピングを施す。今、私はそれが必要でないところでクリッピングを削除することができます。 – EnriqueH73

関連する問題