Plasma::Theme Class

Interface to the Plasma theme. More...

Header: #include <Plasma/Theme>
CMake: find_package(Plasma REQUIRED)
target_link_libraries(mytarget PRIVATE Plasma::Plasma)
Inherits: QObject

Public Types

enum ColorGroup { NormalColorGroup, ButtonColorGroup, ViewColorGroup, ComplementaryColorGroup, HeaderColorGroup, ToolTipColorGroup }
enum ColorRole { TextColor, BackgroundColor, HighlightColor, HoverColor, FocusColor, …, DisabledTextColor }

Properties

Public Functions

Theme(QObject *parent = nullptr)
(since 4.3) Theme(const QString &themeName, QObject *parent = nullptr)
(since 5.20) bool adaptiveTransparencyEnabled() const
(since 5.0) qreal backgroundContrast() const
(since 5.0) bool backgroundContrastEnabled() const
(since 5.0) qreal backgroundIntensity() const
QString backgroundPath(const QString &image) const
(since 5.0) qreal backgroundSaturation() const
(since 5.57) bool blurBehindEnabled() const
QColor color(Plasma::Theme::ColorRole role, Plasma::Theme::ColorGroup group = NormalColorGroup) const
KSharedConfigPtr colorScheme() const
bool currentThemeHasImage(const QString &name) const
(since 5.0) QFont defaultFont() const
QString imagePath(const QString &name) const
(since 5.0) QSizeF mSize(const QFont &font = QGuiApplication::font()) const
(since 5.95) KPluginMetaData metadata() const
(since 5.68) QPalette palette() const
void setThemeName(const QString &themeName)
void setUseGlobalSettings(bool useGlobal)
(since 5.0) QFont smallestFont() const
QString themeName() const
bool useGlobalSettings() const
QString wallpaperPath(const QSize &size = QSize()) const
QString wallpaperPathForSize(int width = -1, int height = -1) const

Signals

Static Public Members

KSharedConfigPtr globalColorScheme()
QPalette globalPalette()

Detailed Description

Plasma::Theme provides access to a common and standardized set of graphic elements stored in SVG format. This allows artists to create single packages of SVGs that will affect the look and feel of all workspace components.

Plasma::Svg uses Plasma::Theme internally to locate and load the appropriate SVG data. Alternatively, Plasma::Theme can be used directly to retrieve file system paths to SVGs by name.

Member Type Documentation

enum Theme::ColorGroup

ConstantValue
Plasma::Theme::NormalColorGroup0
Plasma::Theme::ButtonColorGroup1
Plasma::Theme::ViewColorGroup2
Plasma::Theme::ComplementaryColorGroup3
Plasma::Theme::HeaderColorGroup4
Plasma::Theme::ToolTipColorGroup5

enum Theme::ColorRole

ConstantValueDescription
Plasma::Theme::TextColor0The text color to be used by items resting on the background
Plasma::Theme::BackgroundColor1The default background color
Plasma::Theme::HighlightColor2The text highlight color to be used by items resting on the background
Plasma::Theme::HoverColor3Color for hover effect on view
Plasma::Theme::FocusColor4Color for focus effect on view
Plasma::Theme::LinkColor5Color for clickable links
Plasma::Theme::VisitedLinkColor6Color visited clickable links
Plasma::Theme::HighlightedTextColor7Color contrasting with HighlightColor, to be used for instance with
Plasma::Theme::PositiveTextColor8Color of foreground objects with a "positive message" connotation (usually green)
Plasma::Theme::NeutralTextColor9Color of foreground objects with a "neutral message" connotation (usually yellow)
Plasma::Theme::NegativeTextColor10Color of foreground objects with a "negative message" connotation (usually red)
Plasma::Theme::DisabledTextColor (since Qt 5.64)11color of disabled text

Property Documentation

[read-only] defaultFont : const QFont

Access functions:

QFont defaultFont() const

Notifier signal:

[read-only] palette : const QPalette

Access functions:

QPalette palette() const

Notifier signal:

void themeChanged()

[read-only] smallestFont : const QFont

Access functions:

QFont smallestFont() const

Notifier signal:

[read-only] themeName : const QString

Access functions:

QString themeName() const

Notifier signal:

void themeChanged()

[read-only] useGlobalSettings : const bool

Access functions:

bool useGlobalSettings() const

Notifier signal:

void themeChanged()

[read-only] wallpaperPath : const QString

Access functions:

QString wallpaperPath(const QSize &size = QSize()) const

Notifier signal:

void themeChanged()

Member Function Documentation

[explicit] Theme::Theme(QObject *parent = nullptr)

Default constructor. It will be the global theme configured in plasmarc

parent the parent object

[explicit, since 4.3] Theme::Theme(const QString &themeName, QObject *parent = nullptr)

Construct a theme. It will be a custom theme instance of themeName.

themeName the name of the theme to create

parent the parent object

This function was introduced in 4.3.

[since 5.20] bool Theme::adaptiveTransparencyEnabled() const

This method allows Plasma to enable and disable the adaptive transparency option of the panel, which allows user to decide whether the panel should be always transparent, always opaque or only opaque when a window is maximized. The configuration in the metadata.desktop file of the theme could look like this (for a lighter background):

[AdaptiveTransparency]
enabled=true

Returns Whether or not to enable the adaptive transparency

This function was introduced in 5.20.

[since 5.0] qreal Theme::backgroundContrast() const

This method allows Plasma to set a background contrast effect for a given theme, improving readability. The value is read from the "contrast" key in the "ContrastEffect" group in the Theme's metadata file.

Returns The contrast provided to the contrasteffect

Note: Getter function for property backgroundContrast.

This function was introduced in 5.0.

See also backgroundContrastEnabled.

[since 5.0] bool Theme::backgroundContrastEnabled() const

This method allows Plasma to enable and disable the background contrast effect for a given theme, improving readability. The value is read from the "enabled" key in the "ContrastEffect" group in the Theme's metadata file. The configuration in the metadata.desktop file of the theme could look like this (for a lighter background):

[ContrastEffect]
enabled=true
contrast=0.45
intensity=0.45
saturation=1.7

Returns Whether or not to enable the contrasteffect

This function was introduced in 5.0.

[since 5.0] qreal Theme::backgroundIntensity() const

This method allows Plasma to set a background contrast effect for a given theme, improving readability. The value is read from the "intensity" key in the "ContrastEffect" group in the Theme's metadata file.

Returns The intensity provided to the contrasteffect

Note: Getter function for property backgroundIntensity.

This function was introduced in 5.0.

See also backgroundContrastEnabled.

QString Theme::backgroundPath(const QString &image) const

[since 5.0] qreal Theme::backgroundSaturation() const

This method allows Plasma to set a background contrast effect for a given theme, improving readability. The value is read from the "saturation" key in the "ContrastEffect" group in the Theme's metadata file.

Returns The saturation provided to the contrasteffect

Note: Getter function for property backgroundSaturation.

This function was introduced in 5.0.

See also backgroundContrastEnabled.

[since 5.57] bool Theme::blurBehindEnabled() const

This method allows Plasma to enable and disable the blurring of what is behind the background for a given theme. The value is read from the "enabled" key in the "BlurBehindEffect" group in the Theme's metadata file. Default is @c true.

The configuration in the metadata.desktop file of the theme could look like this:

[BlurBehindEffect]
enabled=false

Returns Whether or not to enable blurring of what is behind

This function was introduced in 5.57.

QColor Theme::color(Plasma::Theme::ColorRole role, Plasma::Theme::ColorGroup group = NormalColorGroup) const

Returns the text color to be used by items resting on the background

role which role (usage pattern) to get the color for

group which group we want a color of

KSharedConfigPtr Theme::colorScheme() const

Returns the color scheme configurationthat goes along this theme.

This can be used with KStatefulBrush and KColorScheme to determine the proper colours to use along with the visual elements in this theme.

bool Theme::currentThemeHasImage(const QString &name) const

Checks if this theme has an image named in a certain way

name the name of the file in the theme directory (without the ".svg" part or a leading slash)

Returns true if the image exists for this theme

[since 5.0] QFont Theme::defaultFont() const

Returns The default application font

Note: Getter function for property defaultFont.

This function was introduced in 5.0.

[signal] void Theme::defaultFontChanged()

Notifier for change of defaultFont property

Note: Notifier signal for property defaultFont.

[static] KSharedConfigPtr Theme::globalColorScheme()

[static] QPalette Theme::globalPalette()

QString Theme::imagePath(const QString &name) const

Retrieve the path for an SVG image in the current theme.

name the name of the file in the theme directory (without the ".svg" part or a leading slash)

Returns the full path to the requested file for the current theme

[invokable, since 5.0] QSizeF Theme::mSize(const QFont &font = QGuiApplication::font()) const

Returns the size of the letter "M" as rendered on the screen with the given font. This values gives you a base size that: * scales dependent on the DPI of the screen * Scales with the default font as set by the user You can use it like this in QML Items:

Item {
    width: PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).height
    height: width
}

This allows you to dynamically scale elements of your user interface with different font settings and different physical outputs (with different DPI).

font The font to use for the metrics.

Returns The size of the letter "M" as rendered on the screen with the given font.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

This function was introduced in 5.0.

[since 5.95] KPluginMetaData Theme::metadata() const

Returns plugin metadata for this theme, with information such as name, description, author, website etc

This function was introduced in 5.95.

[since 5.68] QPalette Theme::palette() const

Returns a QPalette with the colors set as defined by the theme.

Note: Getter function for property palette.

This function was introduced in 5.68.

void Theme::setThemeName(const QString &themeName)

Sets the current theme being used.

See also themeName().

void Theme::setUseGlobalSettings(bool useGlobal)

Tells the theme whether to follow the global settings or use application specific settings

useGlobal pass in true to follow the global settings

See also useGlobalSettings().

[since 5.0] QFont Theme::smallestFont() const

Returns The smallest readable font

Note: Getter function for property smallestFont.

This function was introduced in 5.0.

[signal] void Theme::smallestFontChanged()

Notifier for change of smallestFont property

Note: Notifier signal for property smallestFont.

[signal] void Theme::themeChanged()

Emitted when the user changes the theme. Stylesheet usage, colors, etc. should be updated at this point. However, SVGs should *not* be repainted in response to this signal; connect to Svg::repaintNeeded() instead for that, as Svg objects need repainting not only when themeChanged() is emitted; moreover Svg objects connect to and respond appropriately to themeChanged() internally, emitting Svg::repaintNeeded() at an appropriate time.

Note: Notifier signal for property backgroundContrast. Notifier signal for property backgroundIntensity. Notifier signal for property backgroundSaturation. Notifier signal for property palette. Notifier signal for property themeName. Notifier signal for property useGlobalSettings. Notifier signal for property wallpaperPath.

QString Theme::themeName() const

Returns the name of the theme.

Note: Getter function for property themeName.

See also setThemeName().

bool Theme::useGlobalSettings() const

Returns true if the global settings are followed, false if application specific settings are used.

Note: Getter function for property useGlobalSettings.

See also setUseGlobalSettings().

QString Theme::wallpaperPath(const QSize &size = QSize()) const

Retrieves the default wallpaper associated with this theme.

size the target height and width of the wallpaper; if an invalid size is passed in, then a default size will be provided instead.

Returns the full path to the wallpaper image

Note: Getter function for property wallpaperPath.

[invokable] QString Theme::wallpaperPathForSize(int width = -1, int height = -1) const

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.