Class: QgsProjectStyleSettings

Contains settings and properties relating to how a QgsProject should handle styling.

Added in version 3.26.

Class Hierarchy

Inheritance diagram of qgis.core.QgsProjectStyleSettings

Base classes

QObject

Methods

addStyleDatabasePath

Adds a style database path to the project.

colorModel

Returns the project's color model

colorSpace

Returns the project's color space.

combinedStyleModel

Returns the combined style model which includes all style databases associated with the project.

defaultColorRamp

Returns the project default color ramp.

defaultSymbol

Returns the project default symbol for a given type.

defaultSymbolOpacity

Returns the default symbol opacity.

defaultTextFormat

Returns the project default text format.

projectStyle

Returns the style database to use for project specific styles.

randomizeDefaultSymbolColor

Returns whether the default symbol fill color is randomized.

readXml

Reads the settings's state from a DOM element.

removeProjectStyle

Removes and deletes the project style database.

reset

Resets the settings to a default state.

setColorModel

Set the project's color model to colorModel

setColorSpace

Set the project's current color space to colorSpace.

setDefaultColorRamp

Sets the project default color ramp.

setDefaultSymbol

Sets the project default symbol for a given type.

setDefaultSymbolOpacity

Sets the default symbol opacity.

setDefaultTextFormat

Sets the project default text format.

setProjectStyle

Sets the style database to use for the project style.

setRandomizeDefaultSymbolColor

Sets whether the default symbol fill color is randomized.

setStyleDatabasePaths

Sets the paths to all style databases associated with the project.

styleAtPath

Returns a reference to the style database associated with the project with matching file path.

styleDatabasePaths

Returns a list of all style databases (file paths) associated with the project.

styles

Returns a list of all the styles associated with the project.

writeXml

Returns a DOM element representing the settings.

Signals

styleDatabasesChanged

Emitted whenever the set of style databases associated with the project is changed.

class qgis.core.QgsProjectStyleSettings[source]

Bases: QObject

__init__(project: QgsProject | None = None)

Constructor for QgsProjectStyleSettings for the specified project.

Ownership is transferred to the project.

Parameters:

project (Optional[QgsProject] = None)

addStyleDatabasePath(self, path: str | None)[source]

Adds a style database path to the project.

Paths can be either style .db databases, or .xml exports of style databases.

The file path added by this method must always be absolute paths. Depending on the project settings, they may be converted to relative paths when the project is saved.

Parameters:

path (Optional[str])

colorModel(self) Qgis.ColorModel[source]

Returns the project’s color model

This model is used as the default color model when selecting a color in the whole application. Any color defined in a different color model than the returned model will be converted to this color model when exporting a layout.

The color model defaults to Qgis.ColorModel.Rgb

See also

setColorModel()

Added in version 3.40.

Return type:

Qgis.ColorModel

colorSpace(self) QColorSpace[source]

Returns the project’s color space.

The project color’s space will be added to PDF layout exports when it is defined (i.e. it is different from the default invalid QColorSpace).

The color space defaults to an invalid color space.

See also

setColorSpace()

Added in version 3.40.

Return type:

QColorSpace

combinedStyleModel(self) QgsCombinedStyleModel | None[source]

Returns the combined style model which includes all style databases associated with the project.

This model also includes QgsStyle.defaultStyle().

Note

This is only available on builds based on Qt 5.13 or later.

See also

styles()

Return type:

Optional[QgsCombinedStyleModel]

defaultColorRamp(self) QgsColorRamp | None[source]

Returns the project default color ramp.

Return type:

Optional[QgsColorRamp]

Returns:

a color ramp pointer or None if there is no default set

Note

the color ramp ownership is transferred to the caller

defaultSymbol(self, symbolType: Qgis.SymbolType) QgsSymbol | None[source]

Returns the project default symbol for a given type.

Parameters:

symbolType (Qgis.SymbolType) – the symbol type

Return type:

Optional[QgsSymbol]

Returns:

a symbol pointer or None if there is no default set

Note

the symbol ownership is transferred to the caller

defaultSymbolOpacity(self) float[source]

Returns the default symbol opacity.

Return type:

float

defaultTextFormat(self) QgsTextFormat[source]

Returns the project default text format.

Note

if no default is defined, the returned format will be invalid

Return type:

QgsTextFormat

projectStyle(self) QgsStyle | None[source]

Returns the style database to use for project specific styles.

Return type:

Optional[QgsStyle]

randomizeDefaultSymbolColor(self) bool[source]

Returns whether the default symbol fill color is randomized.

Return type:

bool

readXml(self, element: QDomElement, context: QgsReadWriteContext, flags: Qgis.ProjectReadFlags | Qgis.ProjectReadFlag = Qgis.ProjectReadFlags()) bool[source]

Reads the settings’s state from a DOM element.

See also

writeXml()

Parameters:
Return type:

bool

removeProjectStyle(self)[source]

Removes and deletes the project style database.

Added in version 3.32.

reset(self)[source]

Resets the settings to a default state.

setColorModel(self, colorModel: Qgis.ColorModel)[source]

Set the project’s color model to colorModel

This sets the default color model used when selecting a color in the whole application. Any color defined in a different color model than the one specified here will be converted to this color model when exporting a layout.

If a color space has already been set and its color model differs from colorModel, the project color space will be reset to invalid one (This is only true if QGIS is built against Qt 6.8.0 or greater). setColorSpace() colorSpace()

The color model defaults to Qgis.ColorModel.Rgb

See also

colorModel()

Added in version 3.40.

Parameters:

colorModel (Qgis.ColorModel)

setColorSpace(self, colorSpace: QColorSpace)[source]

Set the project’s current color space to colorSpace. colorSpace must be a valid RGB or CMYK color space. The color space’s ICC profile will be added as a project attached file.

The project color’s space will be added to PDF layout exports when it is defined (i.e. it is different from the default invalid QColorSpace).

If a color model has already been set and it differs from colorSpace’s color model, the project’s color model is set to match the color space’s color model (This is only true if QGIS is built against Qt 6.8.0 or greater). setColorModel() colorModel()

The color space defaults to an invalid color space.

See also

colorSpace()

Added in version 3.40.

Parameters:

colorSpace (QColorSpace)

setDefaultColorRamp(self, colorRamp: QgsColorRamp | None)[source]

Sets the project default color ramp.

Parameters:

colorRamp (Optional[QgsColorRamp]) – the color ramp, set to None to clear default

Note

the color ramp ownership is not transferred

setDefaultSymbol(self, symbolType: Qgis.SymbolType, symbol: QgsSymbol | None)[source]

Sets the project default symbol for a given type.

Parameters:
  • symbolType (Qgis.SymbolType) – the symbol type

  • symbol (Optional[QgsSymbol]) – the symbol pointer, set to None to clear default

Note

the symbol ownership is not transferred

setDefaultSymbolOpacity(self, opacity: float)[source]

Sets the default symbol opacity.

Parameters:

opacity (float)

setDefaultTextFormat(self, textFormat: QgsTextFormat)[source]

Sets the project default text format.

Parameters:

textFormat (QgsTextFormat) – the text format, an invalid format is interpreted as no default

setProjectStyle(self, style: QgsStyle | None)[source]

Sets the style database to use for the project style.

See also

projectStyle()

Parameters:

style (Optional[QgsStyle])

setRandomizeDefaultSymbolColor(self, randomized: bool)[source]

Sets whether the default symbol fill color is randomized.

Parameters:

randomized (bool)

setStyleDatabasePaths(self, paths: Iterable[str | None])[source]

Sets the paths to all style databases associated with the project.

Paths can be either style .db databases, or .xml exports of style databases.

The file paths set by this method must always be absolute paths. Depending on the project settings, they may be converted to relative paths when the project is saved.

Parameters:

paths (Iterable[Optional[str]])

styleAtPath(self, path: str | None) QgsStyle | None[source]

Returns a reference to the style database associated with the project with matching file path.

Parameters:

path (Optional[str])

Return type:

Optional[QgsStyle]

styleDatabasePaths(self) List[str][source]

Returns a list of all style databases (file paths) associated with the project.

The file paths returned by this method will always be absolute paths. Depending on the project settings, they may be converted to relative paths when the project is saved.

See also

styles()

Return type:

List[str]

signal styleDatabasesChanged[source]

Emitted whenever the set of style databases associated with the project is changed.

styles(self) List[QgsStyle]

Returns a list of all the styles associated with the project.

Return type:

List[QgsStyle]

writeXml(self, doc: QDomDocument, context: QgsReadWriteContext) QDomElement[source]

Returns a DOM element representing the settings.

See also

readXml()

Parameters:
Return type:

QDomElement