Add Help Menu entry in QGIS 3 from `startup.py`

by Jochen Schwarze   Last Updated April 15, 2019 10:22 AM

I would like to add a menu entry in the Help menu pointing to some web ressource, say https://gis.stackexchange.com. The following code executed from the python console works perfect:

from qgis.utils import iface
import webbrowser

def open_gis_se():
    webbrowser.open('https://gis.stackexchange.com')

iface.helpMenu().addSeparator()

gis_se_action = QAction('Go to gis.stackexchange')
iface.helpMenu().addAction(gis_se_action)
gis_se_action.triggered.connect(open_gis_se)

Result when typed in the python console:

enter image description here

... but putting it into my startup.py has no effect (Help menu remains 'as it is').

In QGIS 2, the above code put in the startup.py adds the desired menu entry as expected.

Why?



Answers 1


Great idea

you need put startup.py in C:\Users\<username>\AppData\Roaming\QGIS\QGIS3 and add missing import ,and voilá

from qgis.utils import iface
from PyQt5.QtWidgets import QAction
import webbrowser

def open_gis_se():
    webbrowser.open('https://gis.stackexchange.com')

iface.helpMenu().addSeparator()

gis_se_action = QAction('Go to gis.stackexchange')
iface.helpMenu().addAction(gis_se_action)
gis_se_action.triggered.connect(open_gis_se)
Fran Raga
Fran Raga
April 15, 2019 10:20 AM

Related Questions


Updated September 29, 2018 02:22 AM

Updated January 10, 2019 15:22 PM

Updated January 20, 2019 15:22 PM

Updated March 26, 2019 04:22 AM

Updated March 02, 2019 08:22 AM