import QtQuick 2.8 import QtQuick.Window 2.2 import QtQuick.Controls 2.1 Window { id: root visible: true width: Screen.width height: Screen.height title: qsTr("Canvas Bug : click on the drawing, if it works it says ok") Canvas{ id: theCanvas anchors.fill: parent renderStrategy: Canvas.Threaded onPaint: { var ctx = getContext("2d"); ctx.reset(); ctx.clearRect(0, 0, width, height); ctx.save(); ctx.strokeStyle="yellow"; ctx.lineWidth=Screen.pixelDensity*2; ctx.moveTo(0,height); ctx.lineTo(width,0); ctx.stroke(); ctx.restore(); } MouseArea{ anchors.fill: parent readonly property int mouseRegionSize : 8 // the tolerance for click detect function found(mouse) { var ctx = theCanvas.getContext("2d"); var imgPixel; // workaround for 5.8 : /*if(Qt.platform.os=="windows") imgPixel = ctx.getImageData((mouse.x-(mouseRegionSize/(2*Screen.pixelDensity))),(mouse.y-(mouseRegionSize/(2*Screen.pixelDensity))),mouseRegionSize/Screen.pixelDensity,mouseRegionSize/Screen.pixelDensity); else imgPixel = ctx.getImageData((mouse.x*Screen.pixelDensity/2-(mouseRegionSize/2)),(mouse.y*Screen.pixelDensity/2-(mouseRegionSize/2)),mouseRegionSize,mouseRegionSize);*/ // code that worked in 5.7 : imgPixel = ctx.getImageData(mouse.x-mouseRegionSize/2,mouse.y-mouseRegionSize/2,mouseRegionSize,mouseRegionSize); for(var i=0; i