【问题标题】:Is it possible to make a cycle swipe items in qml?是否可以在 qml 中循环滑动项目?
【发布时间】:2018-04-15 23:28:34
【问题描述】:

我在 qml 中使用 swipeview。我可以将项目从第一个到最后一个再向后滑动。是否可以立即从最终滑到第一个?我在文档中没有找到任何信息。

【问题讨论】:

    标签: qt qml


    【解决方案1】:

    您可以使用PathView 做到这一点。 Qt Quick Controls 2 的Tumbler 也可以设为wrap,因为它在内部使用PathView

    【讨论】:

      【解决方案2】:

      您可以使用 PathView。像这样的一些代码:

      import QtQuick 2.0
      
      Rectangle {
          width: 200
          height: 200
      
          ListModel {
              id: model
              ListElement {
                  color: "red"
              }
              ListElement {
                  color: "green"
              }
              ListElement {
                  color: "blue"
              }
          }
      
          Component {
              id: delegate
              Rectangle {
                  id: wrapper
                  width: view.width
                  height: view.height
                  color: model.color
      
                  Text {
                      anchors.centerIn: parent
                      font.pointSize: 26
                      font.bold: true
                      color: "white"
                      text: index
                  }
              }
          }
      
          PathView {
              id: view
              anchors.fill: parent
              snapMode: PathView.SnapOneItem
              highlightRangeMode: PathView.StrictlyEnforceRange
              currentIndex: -1
              model: model
              delegate: delegate
              path: Path {
                  startX: -view.width / 2  // let the first item in left
                  startY: view.height / 2  // item's vertical center is the same as line's
      
                  PathLine {
                      relativeX: view.width * view.model.count  // all items in lines
                      relativeY: 0
                  }
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-21
        • 2020-09-07
        • 1970-01-01
        相关资源
        最近更新 更多