Qt 6.2.0,Ubuntu 20.04。這是我的代碼PathView:
PathView {
id: view
property int item_gap: 60
anchors.fill: parent
pathItemCount: 3
preferredHighlightBegin: 0.5
preferredHighlightEnd: 0.5
highlightRangeMode: PathView.StrictlyEnforceRange
highlightMoveDuration: 1000
snapMode: PathView.SnapToItem
rotation: -90
model: modelContent
delegate: DelegateContent { }
path: Path {
startX: view.width item_gap; startY: view.height / 2
PathAttribute { name: "iconScale"; value: 0.7 }
PathAttribute { name: "iconOpacity"; value: 0.1 }
PathAttribute { name: "iconOrder"; value: 0 }
PathLine {x: view.width / 2; y: view.height / 2; }
PathAttribute { name: "iconScale"; value: 1 }
PathAttribute { name: "iconOpacity"; value: 1 }
PathAttribute { name: "iconOrder"; value: 9 }
PathLine {x: -item_gap; y: view.height / 2; }
}
}
這里是它的代表:
Item {
id: root
property int highlightMoveDuration: 1000
property int image_width: 864 * 0.8
required property int index
required property string label
required property string thumbnail
width: image_width; height: width * 1.7778
scale: PathView.iconScale
opacity: PathView.iconOpacity
z: PathView.iconOrder
Image {
id: img
width: parent.width
height: parent.height
cache: true
asynchronous: true
source: "file://" thumbnail
sourceSize: Qt.size(parent.width, parent.height)
visible: false
}
// other non-relevant stuff
}
}
當我收到來自 C 的信號時,我想通過以下方式為當前專案設定影片:
- 將它和所有其他專案淡化為透明
- 同時(即在前一個影片運行的同時)當前專案(僅)必須沿 Y 軸向上移動
- 呼叫 C 函式
- 將專案重新定位在原始位置(它仍然是透明的)
- 淡化它和所有其他專案恢復原狀
我試過這樣的事情:
SequentialAnimation {
id: selectedContent
running: false
ParallelAnimation {
PropertyAnimation { target: view; properties: "opacity"; duration: 500; to: 0.0}
PropertyAnimation { target: view.delegate; properties: "y"; duration: 500; to: 0.0}
}
ScriptAction { script: ccp_code.selectedContent(view.currentIndex) }
ParallelAnimation {
PropertyAnimation { target: view; properties: "opacity"; duration: 500; to: 1.0}
PropertyAnimation { target: view.delegate; properties: "y"; duration: 0; to: view.height / 2}
}
}
但未找到委托的 y 屬性:
QML PropertyAnimation: Cannot animate non-existent property "y"
只是為了檢查我設定的行為target: view,但y軸上仍然沒有運動。
你能幫我理解如何實作這樣的影片嗎?
uj5u.com熱心網友回復:
問題是這view.delegate是一個Component,它就像一個類定義,而不是一個類實體。您的 PathView 可能會創建該委托的許多實體。所以你不能view.delegate用作影片的目標,因為它需要知道你指的是哪個實體。
由于它是您感興趣的當前專案,因此您可以使用該currentItem屬性來獲取正確的實體。
PropertyAnimation { target: view.currentItem; properties: "y"; duration: 500; to: 0.0}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/368270.html
下一篇:滑動擴展影片旁邊的專案
