Make QtCharts PieSeries clickable



  • I'm just getting started with Qt and as part of getting my feet wet I've started playing around with the QtCharts package (which I've built from source as part of 5.6 and is working fine). I'm trying to setup a clickable pieChart where the user can click on a slice and explode it. I know the PieSeries class has an onClicked signal that passes the slice being selected, but I'm not sure how to wire that up in the QML. Do I need to instantiate a MouseArea for each Slice? Or for the series as a whole? Here's some basic code that I've got working, but I'm not sure where to add the click components.

    import QtQuick 2.0
    import QtCharts 2.1
    
    Item {
        ChartView {
            x: 39
            y: 64
            width: 300
            height: 300
            PieSeries {
                name: "PieSeries"
                PieSlice {
                    value: 13.5
                    label: "Slice1"
                }
    
                PieSlice {
                    value: 10.9
                    label: "Slice2"
                }
    
                PieSlice {
                    value: 8.6
                    label: "Slice3"
                }
        }
    
    }
    
    

    Any help you can provide would be greatly appreciated.



  • just add onClicked: {} into PieSlice



  • @vladstelmahovsky Thanks! That worked like a charm. It also gave me a good starting for digging into the interaction code and figuring out how the mouse handlers work between QML and C++.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.