1

I've created a plugin that implements a Map Tool. It captures mouse click events, which works fine. Now I want to capture Shift+Mouseclick. This doesn't work at all, while Alt+Mouseclick and Ctrl+Mouseclick do work. What's causing this?

The way I'm capturing the events is as follows:

class GeometryTool(QgsMapToolEmitPoint):
    def canvasReleaseEvent(self, event):
        QgsMessageLog.logMessage("Click: " + str(event.button()))
0

For documentation purposes I'll answer my own question. Not sure if I'm supposed to. I had to resort to the source code to find this out.

QgsMapToolEmitPoint inherits from QgsMapTool. All it really adds, is a two line function creating a canvasClicked event that returns an xy-point. That AND overriding the Flags method so that it returns the QgsMapTool.AllowZoomRect flag. This basically tells QGis to attach a sort of secondary zoom function to the tool:

Allow zooming by rectangle (by holding shift and dragging) while the tool is active. This interferes with the capturing of Shift-Click events.

I was using QgsMapToolEmitPoint because the sample in the QGis Cookbook does this, even though the added functionality of this class is never used in the example.

So, to cut a long story short: Use QgsMapTool for your map tools (adding the canvasCicked event yourself if you really need it).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.