Class: QgsProjectStyleSettings

class qgis.core.QgsProjectStyleSettings

Bases: PyQt5.QtCore.QObject

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

Added in version 3.26.

QgsProjectStyleSettings(project: Optional[QgsProject] = None) Constructor for QgsProjectStyleSettings for the specified project.

Ownership is transferred to the project.

Methods

addStyleDatabasePath

Adds a style database path to the project.

childEvent

combinedStyleModel

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

connectNotify

customEvent

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.

disconnectNotify

isSignalConnected

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.

receivers

removeProjectStyle

Removes and deletes the project style database.

reset

Resets the settings to a default state.

sender

senderSignalIndex

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.

timerEvent

writeXml

Returns a DOM element representing the settings.

Signals

styleDatabasesChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

addStyleDatabasePath(self, path: str | None)

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])

childEvent(self, a0: QChildEvent | None)
combinedStyleModel(self) QgsCombinedStyleModel | None

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]

connectNotify(self, signal: QMetaMethod)
customEvent(self, a0: QEvent | None)
defaultColorRamp(self) QgsColorRamp | None

Returns the project default color ramp.

Return type:

Optional[QgsColorRamp]

Returns:

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

Note

the color ramp ownership is transferred to the caller

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

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 NULL if there is no default set

Note

the symbol ownership is transferred to the caller

defaultSymbolOpacity(self) float

Returns the default symbol opacity.

Return type:

float

defaultTextFormat(self) QgsTextFormat

Returns the project default text format.

Note

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

Return type:

QgsTextFormat

disconnectNotify(self, signal: QMetaMethod)
isSignalConnected(self, signal: QMetaMethod) bool
projectStyle(self) QgsStyle | None

Returns the style database to use for project specific styles.

Return type:

Optional[QgsStyle]

randomizeDefaultSymbolColor(self) bool

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

Reads the settings’s state from a DOM element.

See also

writeXml()

Parameters:
Return type:

bool

receivers(self, signal: PYQT_SIGNAL) int
removeProjectStyle(self)

Removes and deletes the project style database.

Added in version 3.32.

reset(self)

Resets the settings to a default state.

sender(self) QObject | None
senderSignalIndex(self) int
setDefaultColorRamp(self, colorRamp: QgsColorRamp | None)

Sets the project default color ramp.

Parameters:

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

Note

the color ramp ownership is not transferred

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

Sets the project default symbol for a given type.

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

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

Note

the symbol ownership is not transferred

setDefaultSymbolOpacity(self, opacity: float)

Sets the default symbol opacity.

Parameters:

opacity (float)

setDefaultTextFormat(self, textFormat: QgsTextFormat)

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)

Sets the style database to use for the project style.

See also

projectStyle()

Parameters:

style (Optional[QgsStyle])

setRandomizeDefaultSymbolColor(self, randomized: bool)

Sets whether the default symbol fill color is randomized.

Parameters:

randomized (bool)

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

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

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]

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]

styleDatabasesChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

styles(self) List[QgsStyle]

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

Return type:

List[QgsStyle]

timerEvent(self, a0: QTimerEvent | None)
writeXml(self, doc: QDomDocument, context: QgsReadWriteContext) QDomElement

Returns a DOM element representing the settings.

See also

readXml()

Parameters:
Return type:

QDomElement