TransWikia.com

Is there a way to refresh the browser on QGIS programatically with PyQGIS?

Geographic Information Systems Asked by breezy on October 1, 2021

I have tried the QgsBrowserModel but it doesn’t seem to work. I am not even sure if that is the right class to use.

The problem is that I add WMS and database connections through a plugin but they won’t show up in the QGIS Browser until I hit the refresh button

QGIS Browser

Do you know a way to refresh the Browser through the QGIS API? And if so, could this be applied to all currently opened instances of QGIS?

One Answer

Try the following

Updated answer due to comment feedback

iface.mainWindow().findChildren(QWidget, 'Browser')[0].refresh()
# If you need to refresh the second browser panel too
iface.mainWindow().findChildren(QWidget, 'Browser2')[0].refresh()

Old answer

widget = iface.mainWindow().findChildren(QWidget, 'Browser')[0]
widget2 = iface.mainWindow().findChildren(QWidget, 'Browser2')[0]

widgetAction = widget.findChildren(QAction, 'mActionRefresh')
widgetAction[0].trigger()

widgetAction2 = widget2.findChildren(QAction, 'mActionRefresh')
widgetAction2[0].trigger()

If there is a shortcut, would be glad to learn about it

Correct answer by ThomasG77 on October 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP