[Qgis-developer] QgsMapToolEmitPoint and cursor

Denis Rouzaud denis.rouzaud at gmail.com
Mon Feb 6 10:28:50 EST 2012


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 <denis.rouzaud at gmail.com 
> <mailto:denis.rouzaud at gmail.com>> wrote:
>
>     Is there anyway to access the QCursor within QgsMapToolEmitPoint.
>     I see there is a mCursor, but it's protected.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20120206/547e2995/attachment-0001.html


More information about the Qgis-developer mailing list