【问题标题】:QML Swipeview Attached PropertiesQML Swipeview 附加属性
【发布时间】:2020-04-07 03:55:42
【问题描述】:

在 QML SwipeView documentation 中,它列出了 SwipeView 子项的一些附加属性。例如

SwipeView.index : int

此附加属性保存 SwipeView 中每个子项的索引。

它附加到 SwipeView 的每个子项。

如何从 SwipeView 子项访问这些属性?我注意到正常的 SwipeView 属性不引用 SwipeView. 例如 vertical

最终我想通过提供孩子的附加索引属性来更改 SwipeView 的当前项目,例如

SwipeView {
    id: view

    currentIndex: aBool ? firstPage.index : secondPage.index
    anchors.fill: parent

    Item {
        id: firstPage
    }
    Item {
        id: secondPage
    }
    Item {
        id: thirdPage
    }
}

【问题讨论】:

    标签: qt qml


    【解决方案1】:

    要从 SwipeView 子项访问附加属性,需要在附加属性之前提供SwipeView.

    因此我上面的例子是

    SwipeView {
        id: view
    
        currentIndex: aBool ? firstPage.SwipeView.index : secondPage.SwipeView.index
        anchors.fill: parent
    
        Item {
            id: firstPage
        }
        Item {
            id: secondPage
        }
        Item {
            id: thirdPage
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-25
      • 2019-04-13
      • 2012-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多