我在裝有OS-X 10.8.4的Mac上運行Qt 5.1和QtQuick 2.0。問題設置Qt- QML CoverFlow旋轉角度
我無法設置一個可變角度的變換:旋轉{}元件,這樣:
transform: Rotation {
axis { x: 0; y: 1; z: 0 }
angle: PathView.angle
}
其中PathView.angle對於每個圖像元素而變化。我遵循代碼here for a cover-flow style container,但該示例也不起作用。
總之,在底部的代碼產生(參見例1中的註釋):
它獲取使用可變PathAttribute角度委託矩形的角度:
PathAttribute { name: "angle"; value: somevalue }
然後角度設定使用:
rotation: PathView.angle
但這不是我想要的,因爲旋轉軸是圍繞z軸定義的(我需要將旋轉角度定義爲y)。因此,我想更接近於(情況2):
現在的旋轉軸線是正確的,但爲每個矩形的角度都是常數(60度,如在代碼中定義的)。我的代碼下面的情況3是我想要的工作,但這給了一個錯誤(每個圖像容器一次),因爲一個可變的角度似乎不適用於變換:旋轉{} :(爲什麼?)
Unable to assign [undefined] to double
如何使這項工作有什麼建議?
謝謝!
下面是最簡單的QML代碼,說明了什麼,我試圖做的:
import QtQuick 2.0
Rectangle {
id: mainRect
width: 1024; height: 300
// Flow View:
Rectangle {
width: parent.width; height: parent.height
color: "gray"
PathView {
id: myPV
delegate: pathdelegate
anchors.fill: parent
model: 11 // provide a range of indices
Keys.onLeftPressed: if (!moving && interactive) incrementCurrentIndex()
Keys.onRightPressed: if (!moving && interactive) decrementCurrentIndex()
preferredHighlightBegin: 0.5
preferredHighlightEnd: 0.5
focus: true
interactive: true
path: Path {
id: pathElement
startX: 0; startY: myPV.height/2
PathAttribute { name: "z"; value: 0 }
PathAttribute { name: "angle"; value: 60 }
PathAttribute { name: "scale"; value: 0.5 }
PathLine { x: myPV.width/2; y: myPV.height/2; }
PathAttribute { name: "z"; value: 100 }
PathAttribute { name: "angle"; value: 0 }
PathAttribute { name: "scale"; value: 1.0 }
PathLine { x: myPV.width; y: myPV.height/2; }
PathAttribute { name: "z"; value: 0 }
PathAttribute { name: "angle"; value: -60 }
PathAttribute { name: "scale"; value: 0.5 }
}
}
// Delegate Component:
Component {
id: pathdelegate
Rectangle {
id: rect
width: 256; height: 256
z: PathView.z
scale: PathView.scale
color: "black"
border.color: "white"
border.width: 3
// Case 1: This works:
rotation: PathView.angle
//Case 2: This works:
//transform: Rotation {
// axis { x: 0; y: 1; z: 0 }
// angle: 60
//}
// Case 3: This is the case that I need to work:
// This DOES NOT work:
// transform: Rotation {
// axis { x: 0; y: 1; z: 0 }
// angle: PathView.angle
//}
}
} // End: Delegate Component
} // End: Flow View:
} // End: mainRect
感謝這工作! –
感謝這真的幫助我解決問題的核心。它只是我們無法訪問Rotation塊中的PathView.angle。 –
@RohitWalavalkar:我的編輯應該解決這個問題。 – Mitch