[QGIS-Developer] Disabling map context menu via PyQGIS

Benoit Ducarouge benoit.ducarouge at oslandia.com
Fri Sep 3 00:58:20 PDT 2021


Hi,

if you just want to hide the menu, you can clear it on the 
contextMenuAboutToShow event :

def clearMenu(menu, event):
     menu.clear()
iface.mapCanvas().contextMenuAboutToShow.connect(clearMenu)

Benoit.

Le 03/09/2021 à 09:31, Benjamin Jakimow a écrit :
>
> Hi Hannes,
>
> in C++ you could override
> void QgsMapCanvas::showContextMenu( QgsMapMouseEvent *event )
>
> which creates and shows the context menu.
>
> in Python showContextMenu is not available. There you could re-implement
> void QgsMapCanvas::mousePressEvent( QMouseEvent *e ) to avoid any 
> calls of showContextMenu()
>
> If you just like to modify the context menu, you might add a slot for the
> void contextMenuAboutToShow( QMenu *menu, QgsMapMouseEvent *event ) 
> signal that manipulates the menu.
>
> Greetings,
>
> Benjamin
>
>
> So you might either override it or
>
> to disable the context menu you can override QgsMapCanvas::mousePressEvent
>
>
> Am 03/09/2021 um 09:14 schrieb Johannes Kröger (WhereGroup):
>
>> Hi list!
>>
>> In QGIS 3.16 a right-click context menu was added to the map canvas: 
>> https://www.qgis.org/en/site/forusers/visualchangelog316/index.html#add-context-menu-to-map-canvas
>>
>> How can we disable that via PyQGIS?
>>
>> https://qgis.org/pyqgis/master/gui/QgsMapCanvas.html lists a 
>> "contextMenuEvent" method but does not provide any documentation at all.
>>
>> The environment is a QGIS based standalone application.
>>
>> Cheers, Hannes
>>
>>
>> _______________________________________________
>> QGIS-Developer mailing list
>> QGIS-Developer at lists.osgeo.org
>> List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> -- 
> Benjamin Jakimow, Doctoral Researcher
> Earth Observation Lab | Geography Department | Humboldt-Universität zu Berlin
>
> e-mail:benjamin.jakimow at geo.hu-berlin.de
>
> phone:  +49 (0) 30 2093 6846
> mobile: +49 (0) 157 5656 8477
> fax:    +49 (0) 30 2093 6848
> mail:   Unter den Linden 6 | 10099 Berlin | Germany
> room: 2'211
> web:https://hu-berlin.de/eo-lab
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210903/a91e7d86/attachment.html>


More information about the QGIS-Developer mailing list