Hi,

Sorry to come again with this stuff, but I am really puzzled.

I am wondering why I have a constant 9 pixels shift between
QCursor.pos().x()
and
mouseEvent.pos().x() + self.canvas.pos().x() + self.iface.mainWindow().pos().x()

Can someone explain this to me?

Also I am still looking for a smart way to perform a snap with the QgsMapTool...
Do you think it could be easily added as an option?

Thanks a lot,

Denis



On 02/06/2012 04:28 PM, Denis Rouzaud wrote:
Hi Nathan,

Thanks for your reply.
I am a little bit confused as I do not really know how to set the mouse position. I have a solution, but it is not giving the same experience as when you create a new feature in a layer:

I use the canvasMoveEvent, I get the point in pixels in the canvas using
result,snappingResults = QgsMapCanvasSnapper(self.canvas).snapToBackgroundLayers(pixPoint,[])

The best I could do is calculating the difference in pixels:
    self.transform = self.canvas.getCoordinateTransform()
    snappedPoint = QgsPoint(snappingResults[0].snappedVertex)
startPoint = self.transform.toMapCoordinates(pixPoint.x(),pixPoint.y()) dx = (snappedPoint.x()-startPoint.x())/self.transform.mapUnitsPerPixel() dy = (snappedPoint.y()-startPoint.y())/self.transform.mapUnitsPerPixel()

And then setting the cursor by applying this difference:
    qcur = QCursor.pos()
    QCursor().setPos(qcur.x()+dx,qcur.y()-dy)

I am quite sure there is a smarter way, but I cannot find it!
Also the problem is that the mouse is oscillating using this method. The only reason I can give is that canvasMoveEvent is sent again before the previously called method has returning, could it be true?

I am a little bit lost in this. I would really appreciate your help!

Thanks again,

Denis




On 02/03/2012 07:37 AM, Nathan Woodrow wrote:
Hey Denis,

The QCursor setPos <http://developer.qt.nokia.com/doc/qt-4.8/qcursor.html#setPos>methods are static so you shouldn't need to get access to the instance to move the cursor position.
*
*
*- Nathan
*
On Fri, Feb 3, 2012 at 4:07 PM, Denis Rouzaud <[email protected] <mailto:[email protected]>> wrote:

    Is there anyway to access the QCursor within QgsMapToolEmitPoint.
    I see there is a mCursor, but it's protected.


_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to