I actually got a response on Stack Exchange regarding this query, so in the 
interests of sharing the response...

Code to run in QGIS Python console is:

browserModel = iface.browserModel()
dirs = ['U:\dir1', 'U:\dir2', 'U:\dir3', 'U:\dir4']
for dir in dirs:
    browserModel.addFavoriteDirectory(dir)

browserModel.reload()

Ref:
https://gis.stackexchange.com/questions/362638/qgis-python-to-add-folder-location-to-browser-favorites



Hello,

I am struggling to get something to work, which would seem to be an easy thing 
to do, but cannot quite make my understanding of the python docs work in 
practice.

What I would like to do, is run some python to add some folders to the 
favorites area in the browser within QGIS. This is to get round an 
environemental constraint of not being able to save a profile i.e. quickly add 
a python script to setup the favorites each time log on.

This is what I have tried thus far:

url = "U:\Tyres"
qgis.gui.QgsBrowserDockWidget(addFavoriteDirectory, uri)

-->

Traceback (most recent call last):
  File "C:\OSGEO4~1\apps\Python37\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "<string>", line 3, in <module>
NameError: name 'addFavoriteDirectory' is not defined

AND

url = "U:\Tyres"
qgis.gui.QgsBrowserDockWidget(addFavorite, uri)

-->

Traceback (most recent call last):
  File "C:\OSGEO4~1\apps\Python37\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "<string>", line 3, in <module>
NameError: name 'addFavorite' is not defined

Should I be calling the addFavorite code differently? This is within the Python 
console and script area of same.

Regards,
Graeme

_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to