2014-01-15 37 views
1

我有一個水平的ListView作爲圖像initial stateQML列表視圖Overscrolls

現在,在給定的,當我把它的滾動列表視圖被overscrolled如下面的圖片 overscoll

在我真正需要的是即使拖到更多,最後一個元素應該留在最後,如下圖所示correct scroll

我該怎麼做。

編輯

ListView控件來源

ListView{ 

     id: list 
     width: 500 
     height: 100 
     clip: true 
     //anchors.bottom: parent.bottom 
     //anchors.bottomMargin: 10 
     snapMode: ListView.SnapToItem 
     anchors.centerIn: parent 
     highlightRangeMode: ListView.StrictlyEnforceRange 
     highlightFollowsCurrentItem: true 
     highlight: Rectangle { color: "#00000000" ;border.color: "red" ; radius: 5 } 
     anchors.horizontalCenter: parent.horizontalCenter 
     orientation: ListView.Horizontal 
     model: ListModel{ 
      id: listModel 
      ListElement{ name: "File"} 
      ListElement{ name: "Edit"} 
      ListElement{ name: "Build"} 
      ListElement{ name: "Debug"} 
      ListElement{ name: "Analyze"} 
      ListElement{ name: "Tools"} 
      ListElement{ name: "Window"} 
      ListElement{ name: "Help"} 
     } 

     delegate: Button{ 
      borderColor: buttonBorderColor;buttonColor: buttonFillColor 
      width: 100;height: 100 ;labelSize: 18 
      label: model.name 
      onButtonClick: { 
       list.currentIndex = model.index; 
       console.log("ListView Button clicked" + model.index) 
      } 
     } 
    } 
+0

您能否提供演示應用程序? – Kakadu

+0

我已更新我的問題 –

+0

您確定您的按鈕是來自QtQuick.Controls的按鈕嗎?最後一個沒有label和labelSize屬性..... – Kakadu

回答

4

你需要通過設置其boundsBehavior財產告訴ListView停在對象範圍:

boundsBehavior: Flickable.StopAtBounds

默認情況下,繼承的對象過沖界限並移回。在Qt網站上查看boundsBehavior property description

+0

這篇文章被自動標記爲低質量,因爲它是如此短/唯一的代碼。你介意加入一些文字來解釋它是如何解決問題的嗎? – gung