Class: QgsStyleModel

A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle database.

If you are creating a style model for the default application style (see QgsStyle.defaultStyle()), consider using the shared style model available at QgsApplication.defaultStyleModel() for performance instead.

Added in version 3.4.

Class Hierarchy

Inheritance diagram of qgis.core.QgsStyleModel

Base classes

QAbstractItemModel

QObject

Enums

CustomRole

Custom model roles.

Role

alias of CustomRole

Methods

addDesiredIconSize

Adds an additional icon size to generate for Qt.DecorationRole data.

addTargetScreenProperties

Adds additional target screen properties to use when generating icons for Qt.DecorationRole data.

style

Returns the style managed by the model.

Attributes

Name

Tags

class qgis.core.QgsStyleModel[source]

Bases: QAbstractItemModel

__init__(style: QgsStyle | None, parent: QObject | None = None)

Constructor for QgsStyleModel, for the specified style and parent object.

The style object must exist for the lifetime of this model.

Parameters:
  • style (Optional[QgsStyle])

  • parent (Optional[QObject] = None)

class Column

Bases: int

class CustomRole(*values)

Bases: IntEnum

Custom model roles.

Note

Prior to QGIS 3.36 this was available as QgsStyleModel.Role

Added in version 3.36.

  • Type: Style entity type, see QgsStyle.StyleEntity

    Available as QgsStyleModel.TypeRole in older QGIS releases.

  • Tag: String list of tags

    Available as QgsStyleModel.TagRole in older QGIS releases.

  • EntityName: Entity name

    Added in version 3.26.

  • SymbolType: Symbol type (for symbol or legend patch shape entities)

    Available as QgsStyleModel.SymbolTypeRole in older QGIS releases.

  • IsFavorite: Whether entity is flagged as a favorite

    Available as QgsStyleModel.IsFavoriteRole in older QGIS releases.

  • LayerType: Layer type (for label settings entities)

    Available as QgsStyleModel.LayerTypeRole in older QGIS releases.

  • CompatibleGeometryTypes: Compatible layer geometry types (for 3D symbols)

    Available as QgsStyleModel.CompatibleGeometryTypesRole in older QGIS releases.

  • StyleName: Name of associated QgsStyle (QgsStyle.name())

    Added in version 3.26.

  • StyleFileName: File name of associated QgsStyle (QgsStyle.fileName())

    Added in version 3.26.

  • IsTitle: True if the index corresponds to a title item

    Added in version 3.26.

    Available as QgsStyleModel.IsTitleRole in older QGIS releases.

Name = 0
Role

alias of CustomRole

Tags = 1
addDesiredIconSize(self, size: QSize)[source]

Adds an additional icon size to generate for Qt.DecorationRole data.

This allows style icons to be generated at an icon size which corresponds exactly to the view’s icon size in which this model is used.

Parameters:

size (QSize)

addTargetScreenProperties(self, properties: QgsScreenProperties)[source]

Adds additional target screen properties to use when generating icons for Qt.DecorationRole data.

This allows style icons to be generated at an icon device pixel ratio and DPI which corresponds exactly to the view’s screen properties in which this model is used.

Added in version 3.32.

Parameters:

properties (QgsScreenProperties)

style(self) QgsStyle | None[source]

Returns the style managed by the model.

Added in version 3.10.

Return type:

Optional[QgsStyle]