2016-03-04 75 views
0

沒有線下面是一個剪斷代碼中我想在畫布上繪製帆布設爲Qml 2D到顯示

function drawAxis(context) 
{ 
    context.lineWidth = 1; 
    context.strokeStyle = Qt.rgba(0, 0, 0, 1); 

    context.beginPath(); 

    // draw axis 
    context.moveTo(0, center_h); 
    context.lineTo(width, center_h); 
    context.moveTo(center_w, 0); 
    context.lineTo(center_w, height); 
    context.closePath(); 
} 

一個十字線,但沒有顯示任何事實。這裏可能有什麼問題?

回答

1

事實證明,如果沒有調用stroke()函數,線條不會被繪製。因此,最終的工作代碼如下:

function drawAxis(context) { 
    context.lineWidth = 1 
    context.strokeStyle = Qt.rgba(0, 0, 0, 1) 
    context.beginPath() 
    context.moveTo(0, center_h) 
    context.lineTo(width, center_h) 
    context.moveTo(center_w, 0) 
    context.lineTo(center_w, height) 
    context.closePath() 
    context.stroke()      // <--- lines are drawn here! 
} 
+0

真是一個有趣的小時計算出來的是。謝謝。 – detly