我有這個項目使用QStatemachine來管理用戶界面,我想添加一個自定義列表。 UI應該只能由關鍵事件操縱。據我所知,我需要在qml端的ListView。如何使用QStatemachine來影響ListView?
ListView的委託僅對鼠標輸入或直接鍵輸入做出反應。但是我使用C++中的QStatemachine來操作它,因爲它正在處理UI的所有關鍵事件。 當我按下右箭頭鍵時,我想要發生的事情是將列表移動到左側。
(該CURRENTITEM常是在屏幕的中間。)
所以我的ListView正在尋找這樣的時刻。
Component {
id:myDelegation
Item {
x: 50
width: 80
height: 60
Rectangle {
width: 60
height: 60
Text {
text: name
anchors.centerIn: parent
}
color: parent.ListView.isCurrentItem ? "red" : "steelblue";
scale: parent.ListView.isCurrentItem ? 1.5 : 1;
}
}
}
ListView {
id: listView1
x: 0
y: 50
width: 1920
height: 214
orientation: ListView.Horizontal
spacing: 4
model: TileList{}
delegate: myDelegation
preferredHighlightBegin: width/2 - 10
preferredHighlightEnd: width/2 + 10
highlightRangeMode: ListView.StrictlyEnforceRange
}
C++ Statemachine是一個將信號發送到qml的QStatemachine。
如何將信號綁定到Listview的委託?
您可以直接從QML使用'StateMachine'。它比使用C++類更簡單快捷。 – dtech
那麼我已經完成了在C++ Statemachine,它是相當大的。所以我不能從頭開始改變它。 – user1997675
然後只是將其與QML連接。它已經是一個派生的QObject,因此您可以將其作爲上下文屬性公開並使用其信號和插槽。 – dtech