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?
Answer
Great idea
you need place startup.py in C:\Users\
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)
No comments:
Post a Comment