首页 > 解决方案 > Qml ChartView BarSeries 检索鼠标位置 onHovered 事件

问题描述

当任何条悬停但我无法实现时,我想检索鼠标位置。这是我的 qml 代码。实际上,我想在鼠标指针旁边显示一个显示悬停栏百分比值的文本。

ChartView {

    property int hovered_bar_idx    :   -1

    anchors {
        left        :   parent.left
        right       :   parent.right
        rightMargin :   10
        bottom      :   parent.bottom
    }

    id              :   chart
    height          :   450
    title           :   "Staves Statuses"
    legend.alignment:   Qt.AlignBottom
    antialiasing    :   true
    backgroundColor :   "black"
    legend.visible  :   false

    BarSeries {
        id      :   mySeries
        barWidth:   0.85
        axisY   :   ValueAxis { max :   1.0;    min :   0.0; }
        axisX   :   BarCategoryAxis {
            id                  :   axis_x;
            categories          :   sys_hardware_display.categories;
            gridVisible         :   false
        }
        onHovered   :   {
            console.log( "s : " + status + " idx : " + index )

            // I want to retrieve position of mouse here.
        }

        BarSet  {
            id          :   stave_values
            label       :   "Staves"
            color       :   "#00FF00"
            borderWidth :   0
        }
    }
}

标签: qtqmlqtcharts

解决方案


推荐阅读