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:
... 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?
C:\Users\username\AppData\Roaming\QGIS\QGIS3
as described in this post. Your code should have produced an error aboutQAction
not being defined which can be rectified by addingfrom PyQt5.QtWidgets import QAction
.