【发布时间】:2017-09-21 14:26:52
【问题描述】:
我有一个动态创建的饼图,它使用下面描述的函数 createPieChart()。单击切片时,我想调用一个函数来打印出该切片的标签和值。
我面临两个问题:
- 虽然我连接了“点击”或“按下”或“释放”信号,但未到达插槽。我正在使用 qtcharts 2.0(我现在无法更新)。
- 我可以连接“悬停”信号,但没有传递任何参数,所以我不知道我属于哪个切片。
这些是其他功能:
function createPieChart(data){
pieserieschart.clear();
slices.splice(0, slices.length) //clear slices array
for (var prop in data) {
slices.unshift(pieserieschart.append(prop, data[prop]));
//I get "Cannot read property 'label' of undefined using this method
slices[0].hovered.connect(function(){mouseHoverSlice(slices[0].label));
//WORKS, but I want to pass the label of that slice (and the value if possible)
slices[0].hovered.connect(mouseHoverSlice);
//it is not working at all
slices[i].clicked.connect(sliceClicked);
}
function sliceClicked(){
console.log("Slice Clicked"); //I cannot see this printed
}
function mouseHoverSlice(info){
console.log("Slice hover: " + info);
}
知道怎么做吗?谢谢!
【问题讨论】:
-
显然我不是唯一面临这个问题的人。这篇文章也没有触发 clicked() 信号:stackoverflow.com/questions/40626911/…
标签: charts qml interactive signal-handling