[英]How to Scroll inside ChartView using mousearea in QML
我編寫了這段代碼,並期望當鼠標滾輪以一種或另一種方式旋轉時,ChartView可以向右或向左滾動。
ChartView {
id: chartView
animationOptions: ChartView.NoAnimation
theme: ChartView.ChartThemeDark
ValueAxis {
...
}
ValueAxis {
...
}
LineSeries {
...
}
MouseArea {
anchors.fill: parent
onWheel: {
if (wheel.modifiers & Qt.ControlModifier){
if (wheel.angleDelta.y > 0)
{
chartView.scrollRight(5)
}
else
{
chartView.scrollLeft(5)
}
wheel.accepted=true
}
else{
wheel.accepted=false
}
}
}
}
雖然不行。 我想念什么?
我將使用ScrollView:
Rectangle {
width: 200 //size of the viewed part
height: 200 //size of the viewed part
color: "transparent"
clip: true
ScrollView {
anchors.fill: parent
contentWidth: chartRec.width
contentHeight: chartRec.height
Rectangle {
id: chartRec
height: 400 //size of the chart
width: 400 //size of the chart
color: "transparent"
ChartView {
id: chartView
anchors.fill: parent
animationOptions: ChartView.NoAnimation
theme: ChartView.ChartThemeDark
ValueAxis {
...
}
ValueAxis {
...
}
LineSeries {
...
}
}
}
}
}
第二個Rectangle的大小應大於第一個Rectangle的大小。 如果沒有,則不會顯示ScrollView。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.