Sunday, 12 November 2017

pyqgis - How to close/remove QGIS welcome page (recent projects) with Python?


Is it possible to close the QGIS welcome page with Python?



I have a permanently docked Python plugin, that uses showRubberBand to directly write into map canvas. Therefor I have to close/remove the welcome page first.



Answer



There are a couple of different approaches to that:


Start a new project


iface.newProject()

Add a layer


Whenever a new layer gets added to the mapcanvas, the welcome page will disappear


Change the configuration


In contrast to the other two approaches, this changes the configuration of the QGIS installation permanently.



# 0: Welcome page
# 1: Most recent
# 2: Specific (specify with '/qgis/projOpenAtLaunchPath')
# 3: New
QSettings().setValue('/qgis/projOpenAtLaunch', 3)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...