[QGIS-Developer] Temporarily disable map canvas right click showing Copy Coordinates
Catania, Luke A ERDC-RDE-GRL-VA CIV
Luke.A.Catania at erdc.dren.mil
Wed Apr 12 22:29:06 PDT 2023
I am not using QgsMapTool.
T o capute mouse events, I declared my class as
class AoiSizeValidator(QWidget):
And added
def eventFilter(self, source, event):
with code that captures mouse click events.
I tried using
iface.mapCanvas().setContextMenuPolicy(Qt.NoContextMenu)
and
iface.mapCanvas().setContextMenuPolicy(Qt.PreventContextMenu)
But it did not work. I found that suggestion on a site where someone was looking to disable the context menu for QWebEngineView, so thought it would work for the map canvas.
I did find half a solution by setting
iface.mapCanvas().contextMenuAboutToShow.connect(self.disable_context_menu)
def disable_map_canvas_context_menu(self, menu: QMenu, event: QgsMapMouseEvent):
menu.clear()
which basically completely clears the context menu from all its widgets, but I would like he menu back after my right click event happens to end the edit session.
-----Original Message-----
From: Nyall Dawson <nyall.dawson at gmail.com>
Sent: Wednesday, April 12, 2023 9:09 PM
To: Catania, Luke A ERDC-RDE-GRL-VA CIV <Luke.A.Catania at erdc.dren.mil>
Cc: qgis-developer at lists.osgeo.org
Subject: Re: [QGIS-Developer] Temporarily disable map canvas right click showing Copy Coordinates
On Thu, 13 Apr 2023 at 10:47, Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer <qgis-developer at lists.osgeo.org> wrote:
>
> I have an event filter on the map canvas that performs a commit during feature editing when right clicking on the canvas. While this performs the commit, it then pops up Copy Coordinates. I don’t want the user to see this. I want my mouse click event to be recognized and not have QGIS use it to popup the Copy Coordinates. Is there a way to call QgsMapTool.deactivate on that built in tool just for this instance and then reactivate it?
Are you using a custom QgsMapTool subclass? If so, implement the "flags" method and don't return the ShowContextMenu flag.
Nyall
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info:
> Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked
> Unsubscribe:
> Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked
More information about the QGIS-Developer
mailing list