Class: QgsProjectStyleSettings

class qgis.core.QgsProjectStyleSettings

Bases: PyQt5.QtCore.QObject

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

New in version 3.26.

QgsProjectStyleSettings(project: 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

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)

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 (str) –

childEvent(self, QChildEvent)
combinedStyleModel(self) QgsCombinedStyleModel

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

QgsCombinedStyleModel

connectNotify(self, QMetaMethod)
customEvent(self, QEvent)
defaultColorRamp(self) QgsColorRamp

Returns the project default color ramp.

Return type

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

Returns the project default symbol for a given type.

Parameters

symbolType (Qgis.SymbolType) – the symbol type

Return type

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, QMetaMethod)
isSignalConnected(self, QMetaMethod) bool
projectStyle(self) QgsStyle

Returns the style database to use for project specific styles.

Return type

QgsStyle

randomizeDefaultSymbolColor(self) bool

Returns whether the default symbol fill color is randomized.

Return type

bool

readXml(self, element: QDomElement, context: QgsReadWriteContext, flags: Union[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, PYQT_SIGNAL) int
reset(self)

Resets the settings to a default state.

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

Sets the project default color ramp.

Parameters

colorRamp (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)

Sets the project default symbol for a given type.

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

  • symbol (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)

Sets the style database to use for the project style.

See also

projectStyle()

Parameters

style (QgsStyle) –

setRandomizeDefaultSymbolColor(self, randomized: bool)

Sets whether the default symbol fill color is randomized.

Parameters

randomized (bool) –

setStyleDatabasePaths(self, paths: Iterable[str])

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[str]) –

styleAtPath(self, path: str) QgsStyle

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

Parameters

path (str) –

Return type

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, QTimerEvent)
writeXml(self, doc: QDomDocument, context: QgsReadWriteContext) QDomElement

Returns a DOM element representing the settings.

See also

readXml()

Parameters
Return type

QDomElement