所以我有一個動態變化的餅圖。我想顯示鼠標移動到切片上時每個切片的值,但我不確定如何在觸發onHovered時創建工具提示。我用QML動態創建工具提示
QT 5.9.1 &進口QtQuick.Controls 2.2
更新:我加入一些代碼來解釋我是如何創建的切片。 下面是代碼:
function onUpdateValues(values){
switch(values.type){
case PIE_CHART:
createPieChart(values.data);
break;
...
default:
console.debug("CHART TYPE ERROR");
break;
}
}
}
function createPieChart(data){
pieserieschart.clear();
for (var prop in data) {
var new_slice = pieserieschart.append(prop, data[prop]);
new_slice.tooltip = prop + ": " + data[prop]
//I tried using hovered signal (and without), but it's not doing any difference
new_slice.hovered.connect(function(state) { new_slice.tooltip.visible = state })
//If I replace the above line by the next one, I can see the console.log info, but the tooltip is not enabled
new_slice.hovered.connect(function(state) { sliceHovered(new_slice, state) })
}
}
function sliceHovered(slice, value){
slice.enabled = true
console.log("Slice hovered: " + slice.tooltip + " " + value)
}
ChartView { /* Chart */
id:chartView
PieSeries {
id: pieserieschart;
size: 1;
holeSize: 0.55;
onClicked: sliceClicked(slice);
}
}
我能看到的console.log,但我沒能看到提示,以及應用程序的輸出不顯示任何錯誤,但提示沒有觸發
哪裏是 '切片' 定義? – sk2212
動態地在一個函數中:function createPieChart(data){ pieserieschart.clear(); (var prop in data){ var new_slice = pieserieschart.append(prop,data [prop]); new_slice.tooltip = prop +「:」+ data [prop] } – laurapons
我試過聲明new_slice.tooltip,並且onHovered,我可以閱讀slice.tooltip,但它不顯示 – laurapons