Skip to content

fxstyle

UI stylesheet, HEX colors and others.

Examples:

>>> import style
>>> colors = style.load_colors_from_jsonc()
>>> houdini_orange = colors["houdini"]["main"]
#3cc0fd

FXProxyStyle

Bases: QProxyStyle

A custom style class that extends QProxyStyle to provide custom icons.

set_icon_color

set_icon_color(color: str)

Sets the color of the icons.

Parameters:

Name Type Description Default
color str

The color to set the icons to.

required

standardIcon

standardIcon(
    standardIcon: StandardPixmap,
    option: Optional[QStyleOption] = None,
    widget: Optional[QWidget] = None,
) -> QIcon

Returns an icon for the given standardIcon.

Parameters:

Name Type Description Default
standardIcon StandardPixmap

The standard pixmap for which an icon should be returned.

required
option QStyleOption

An option that can be used to fine-tune the look of the icon. Defaults to None.

None
widget QWidget

The widget for which the icon is being requested. Defaults to None.

None

Returns:

Name Type Description
QIcon QIcon

The icon for the standardIcon. If no custom icon is found, the default icon is returned.

get_current_palette

get_current_palette(object: QObject) -> None

Prints the current palette of the given Qt object.

This function retrieves the current palette of the given Qt object and prints each color role in each state group in the format QPalette.State, QPalette.Role, QColor(r, g, b).

Parameters:

Name Type Description Default
object QObject

The Qt object whose palette is to be retrieved.

required

load_colors_from_jsonc

load_colors_from_jsonc(jsonc_file: str = COLOR_FILE) -> dict

Load colors from a JSONC (JSON with comments) file.

Parameters:

Name Type Description Default
jsonc_file str

The path to the JSONC file. Defaults to COLOR_FILE.

COLOR_FILE

Returns:

Name Type Description
dict dict

A dictionary containing color definitions.

load_stylesheet

load_stylesheet(
    style_file: str = STYLE_FILE,
    color_a: str = _COLOR_A_DEFAULT,
    color_b: str = _COLOR_B_DEFAULT,
    extra: Optional[str] = None,
) -> str

Load the stylesheet and replace some part of the given QSS file to make them work in a DCC.

Parameters:

Name Type Description Default
style_file str

The path to the QSS file. Defaults to STYLE_FILE.

STYLE_FILE
color_a str

The primary color to use. Defaults to #649eff.

_COLOR_A_DEFAULT
color_b str

The secondary color to use. Defaults to #4188ff.

_COLOR_B_DEFAULT
extra str

Extra stylesheet content to append. Defaults to None.

None

Returns:

Name Type Description
str str

The stylesheet with the right elements replaced.

replace_colors

replace_colors(
    stylesheet: str,
    colors_dict: dict = load_colors_from_jsonc(COLOR_FILE),
    prefix="",
) -> str

summary

Parameters:

Name Type Description Default
stylesheet str

The stylesheet to replace the colors in.

required
colors_dict dict

The dict to use to search for colors to be replaced. Defaults to load_colors_from_jsonc(COLOR_FILE).

load_colors_from_jsonc(COLOR_FILE)
prefix str

The identifier prefix for colors to be replaced. Defaults to "".

''

Returns:

Name Type Description
str str

The stylesheet with replaced colors.

set_dark_palette

set_dark_palette(object: QObject) -> QPalette

Set the object palette to a dark theme.

Parameters:

Name Type Description Default
object QObject

The QObject (QApplication, QWindow, etc.) to set the palette on.

required

Returns:

Name Type Description
QPalette QPalette

The custom palette.

set_light_palette

set_light_palette(object: QObject) -> QPalette

Set the object palette to a light theme.

Parameters:

Name Type Description Default
object QObject

The QObject (QApplication, QWindow, etc.) to set the palette on.

required

Returns:

Name Type Description
QPalette QPalette

The custom palette.

set_style

set_style(widget: QWidget, style: str = None) -> FXProxyStyle

Set the style.

Parameters:

Name Type Description Default
widget QWidget

The QWidget subclass to set the style to.

required
style str

The style to set. Defaults to None.

None

Returns:

Name Type Description
FXProxyStyle FXProxyStyle

The custom style.

Note

You can retrieve the styles available on your system with QStyleFactory.keys(). Only those string values are accepted in the style argument.