2016-09-03 3 views
1

Flickableには、列レイアウトの2つのRepeatersがあります。私は最初のリピータの最後の項目にスクロールすることを望んでいます。これは可能ですか?Flickableのリピータの最後の項目にスクロールするには

最初のリピータに含まれるアイテムの数を数え、それを使用している代理人の高さで乗算する方法があるとします。 (デリゲートは固定された高さです)。または、リピーターの高さをとり、最後のデリゲートの高さを引いてください。私はこれよりも良い方法を望んでいますが。

import QtQuick 2.7 
import QtQuick.Controls 2.0 

Item { 
    id:passwordsView 
    Flickable { 
     id: flickable1 
     anchors.fill: parent 
     contentHeight: passwordsView_column.height 
     ScrollBar.vertical: ScrollBar { } 
     Column { 
      id:passwordsView_column 
      spacing: 15 
      anchors.left: parent.left 
      anchors.right: parent.right 
      Repeater { 
       id: passwordsView_breadcrumb 
       anchors.left: parent.left 
       anchors.right: parent.right 
       model: BreadcrumbModel {} 
       delegate: PasswordFolderDelegate { 
        y: 8; 
        anchors.left: parent.left; 
        anchors.right: parent.right; 
       } 
      } 

      Repeater { 
       id: passwordsView_contents 
       model: PasswordModel {} 
       PasswordFolderDelegate { 
        y: 8 
        anchors.left: parent.left 
        anchors.right: parent.right 
       } 
       anchors.left: parent.left 
       anchors.right: parent.right 
      } 
     } 
    } 
} 

答えて

2

またはリピータの高さを取り、最後のデリゲートの高さを引きます。

Repeaterは高さがありません。アイテムを配置するだけなので、少し難しいかもしれません。

私は考えることができる最も簡単な方法は、mapToItem()を使用することです:

import QtQuick 2.7 
import QtQuick.Controls 2.0 

ApplicationWindow { 
    width: 400 
    height: 400 
    visible: true 

    Flickable { 
     id: flickable1 
     anchors.fill: parent 
     contentHeight: passwordsView_column.height 
     ScrollBar.vertical: ScrollBar { } 
     Column { 
      id:passwordsView_column 
      spacing: 15 
      anchors.left: parent.left 
      anchors.right: parent.right 
      Repeater { 
       id: passwordsView_breadcrumb 
       anchors.left: parent.left 
       anchors.right: parent.right 
       model: 10 
       delegate: Rectangle { 
        width: 50 
        height: 50 
        color: "transparent" 
        border.color: "salmon" 

        Text { 
         text: index 
         anchors.centerIn: parent 
        } 
       } 
      } 

      Repeater { 
       id: passwordsView_contents 
       model: 10 
       delegate: Rectangle { 
        width: 50 
        height: 50 
        color: "transparent" 
        border.color: "#444" 

        Text { 
         text: index 
         anchors.centerIn: parent 
        } 
       } 
      } 
     } 
    } 

    Button { 
     text: "Position at end" 
     anchors.top: parent.top 
     anchors.right: parent.right 
     onClicked: { 
      var lastItem = passwordsView_breadcrumb.itemAt(passwordsView_breadcrumb.count - 1); 
      flickable1.contentY = lastItem.mapToItem(flickable1.contentItem, 0, 0).y 
     } 
    } 
} 

(注)このビューが瞬時に移動しますということ。滑らかなスクロールが必要な場合は、何らかの理由で必要な速度を計算してflick()に渡す必要があります。

+0

例では、新しく読み込まれたアプリケーションがあり、ボタンを押すと機能します。しかし、スクロールしたり位置を変えたりすると、最初に上に移動し、もう一度クリックすると最後の項目に移動します。イベントの最後の項目(この場合はbutton onClick())に常に移動する場所に関係なく、ビューではそれが表示されるようにしたいとの希望でした。 – Encompass

+1

ああ、そうです。くそー。 :( – Mitch

+1

ああ、 'flickable1.contentY = lastItem.mapToItem(flickable1.contentItem、0、0).y'だったはずです。 – Mitch

関連する問題