Storing and reading global preferences

PyQGIS allows you to store application-level preferences and retrieve them. QGIS also has project-level preferences, which can override the application-level preferences in some cases. In this recipe, we'll focus on reading and writing the global preferences that serve as the application defaults. QGIS actually takes advantage of Qt's built-in preferences management.

Getting ready

This code can be run in any type of PyQGIS application. In this example, we'll run it in the QGIS Python console for an easy demonstration. We'll also change the default CRS for new projects and then read the value back from the global settings.

How to do it...

In this recipe, we will set the default projection used by QGIS for new ...

Get QGIS Python Programming Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.