Skip to main content

Qt CSS Engine

A CSS animation engine for PyQt6/PySide6 that extends Qt's static stylesheet system (QSS) with dynamic CSS transitions and extra properties like box-shadow, opacity and CSS gradients. Qt's stylesheet engine has no concept of time or interpolation — this project implements an out-of-band animation system that intercepts transition: declarations from a stylesheet, tracks widget pseudo-states (hover, pressed, focus), and drives smooth property animations via Qt's animation framework. Dynamic class change is also supported so .btn -> .btn.active -> .btn.other-state will animate based on the transition property.

All that is required is to install TransitionEngine as an event filter and it will take care of the rest. It can be installed directly on a QApplication or any child QWidget.

CSS Hot reload is supported via TransitionEngine.reload_rules(new_rules)

Subcontrols (e.g ::item, ::handle) are not supported because they are not real QWidgets. They will be just passed through as classic QSS stylesheet blocks.

extract_rules() splits comma-separated selectors into separate blocks in the cleaned QSS, preserving their order. This also applies to static rules and subcontrols.

This is not a full CSS3 spec port. It has some very important Qt-specific differences, especially when it comes to transition property accumulation vs overriding.

Python and Qt version

Python 3.14+

PySide6/PyQt6 6.10+

Installation

uv add qt-css-engine

Usage

from qt_css_engine import TransitionEngine, extract_rules

app = QApplication([])
cleaned_qss, rules = extract_rules(stylesheet)
app.setStyleSheet(cleaned_qss)
engine = TransitionEngine(rules)
app.installEventFilter(engine)

Local styles

Optionally, widget-local styles are collected once at first Polish with TransitionEngine(rules, collect_widget_styles=True); install the engine before widgets are polished. Automatic collection does not detect later stylesheet changes.

Apply or update styles explicitly with engine.set_widget_stylesheet(widget, qss). set_widget_stylesheet() works regardless of whether collect_widget_styles is set.

Simple transition examples

/* A simple widget with a hover transition */
.btn {
    background-color: steelblue;
    color: white;
    border-radius: 4px;
    transition: background-color 300ms ease;
}

.btn:hover {
    background-color: royalblue;
}

/* A widget with a box-shadow transition */
#btn {
    background-color: steelblue;
    color: white;
    border-radius: 4px;
    box-shadow: 0px 0px 0px black;
    transition: box-shadow 300ms ease;
}

#btn:hover {
    box-shadow: 4px 4px 4px black;
}

More complex examples

Check the ./demo/main.py for hot reloading, dynamic class change and more.

Transition syntax and supported values

Shorthand

transition: <property> <duration> [<easing>] [<delay>];
transition: <property> <duration> [<delay>] [<easing>];

/* multiple */
transition: background-color 300ms ease, border-radius 200ms linear 50ms;

/* all animatable properties */
transition: all 300ms ease-in-out;

Longhands

transition-property: background-color, border-radius;
transition-duration: 300ms, 200ms;
transition-timing-function: ease, linear;
transition-delay: 0ms, 50ms;

Accumulation and cancellation

Longhands update the previous shorthands instead of overriding them completely.

Transition declarations accumulate across matching rules. Explicit property timings take precedence over all. all supplies timing for the remaining supported properties.

transition: none or transition-property: none will disable the previous transitions. Specifying a new transition will re-enable it for that property.

.btn {
    transition: all 300ms;
}
.btn.quiet {
    transition: none;
    transition: color 150ms; /* Only color animates. */
}

Timing-only longhands after none do not enable properties.

Time units

Unit Example
Milliseconds 300ms
Seconds 0.3s

Easing curves

Value Description
linear Constant speed
ease Slow in, slow out (default)
ease-in Slow start
ease-out Slow end
ease-in-out Slow start and end
cubic-bezier(x1, y1, x2, y2) Custom curve — values outside [0, 1] produce overshoot
steps(n) / steps(n, jump-end|jump-start|jump-none|jump-both) Discrete stepped animation
step-start / step-end Aliases for steps(1, jump-start) / steps(1, jump-end)

Delay

Positive delay: animation starts after the delay elapses. The property is frozen at its current rendered value during the delay period.

Negative delay: animation starts immediately but offset |delay| ms into the timeline, as if it had already been running that long.

transition: background 400ms ease 100ms;   /* 100ms positive delay */
transition: background 400ms ease -100ms;  /* starts 100ms in */
/* OR */
transition: background 400ms 100ms ease;
transition: background 400ms -100ms ease;

Supported pseudo-classes

Pseudo-class Description Transition Static
:hover Hover in-out ✅ ✅
:focus Focus in-out ✅ ✅
:pressed Hold-down mouse button ✅ ✅
:checked Checked state on-off ✅ ✅
:active Window gains/loses focus ✅ ✅
:clicked (NEW) Play full animation loop on click ✅ ❌

Supported properties

Color values accepted everywhere a color is listed: named (red, steelblue, …), #RRGGBB, #AARRGGBB, rgb(), rgba(), hsl(), hsla().

Numeric values accepted everywhere a length is listed: <n>px, <n>pt, <n>em.

Property Description Supported values Transition Static
background-color / background Background color color values; linear-gradient(), radial-gradient(), conic-gradient() (static only) ✅ solid colors ✅
color Text color color values ✅ ✅
border-color Border color shorthand (→ 4 sides) color values ✅ ✅
border-top-color, border-right-color, border-bottom-color, border-left-color Per-side border color color values ✅ ✅
border-width Border width shorthand (→ 4 sides) length values ✅ ✅
border-top-width, border-right-width, border-bottom-width, border-left-width Per-side border width length values ✅ ✅
border-radius Border radius shorthand (→ 4 corners) length values ✅ ✅
border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius Per-corner border radius length values ✅ ✅
padding Padding shorthand (→ 4 sides) length values ✅ ✅
padding-top, padding-right, padding-bottom, padding-left Per-side padding length values ✅ ✅
margin Margin shorthand (→ 4 sides) length values ✅ ✅
margin-top, margin-right, margin-bottom, margin-left Per-side margin length values ✅ ✅
width, height Widget size length values ✅ ✅
min-width, max-width, min-height, max-height Size constraints length values ✅ ✅
font-size Font size length values ✅ ✅
font-weight Font weight 100–900 ✅ ✅
letter-spacing Letter spacing length values ✅ ✅
word-spacing Word spacing length values ✅ ✅
spacing Qt widget item spacing length values ✅ ✅
opacity Widget opacity — not native QSS, applied via QGraphicsOpacityEffect 0.0–1.0 ✅ ✅
box-shadow Drop shadow — not native QSS, applied via QGraphicsDropShadowEffect. No inset, spread is ignored. First shadow wins when multiple are declared. <x> <y> [blur] [spread] <color> ✅ ✅
cursor Mouse cursor — Qt QSS ignores cursor, applied via setCursor() default, pointer, text, crosshair, wait, progress, help, move, grab, grabbing, copy, alias, not-allowed, no-drop, cell, all-scroll, n-resize, s-resize, e-resize, w-resize, ne-resize, nw-resize, se-resize, sw-resize, ns-resize, ew-resize, nesw-resize, nwse-resize, row-resize, col-resize, none ❌ ✅

About existing hardcoded QGraphicsEffect instances

Application-installed graphics effects are preserved. CSS opacity, box-shadow, and text-shadow are skipped wherever they would conflict with those effects.

Disabling shadows on a widget

box-shadow and text-shadow can be disabled on a specific widget by setting cssEngineDisableShadow property to True

widget.setProperty("cssEngineDisableShadow", True)

This is useful for translucent frameless windows or edge-to-edge surfaces where a Qt drop shadow can extend outside the window's backing store and cause UpdateLayeredWindowIndirect failures on Windows.

This exists mainly to avoid user error when custom css files are supported by the parent application.

Not setting box-shadow/text-shadow on those widgets will also work, of course.

Environment variables

Variable Description Default
CSS_ENGINE_LEFT_CLICK_ONLY Exclude middle and right click from triggering on-click animations False
CSS_ENGINE_EVENT_LOGGING Enable internal event debug logging (qt_css_engine.event logger) False

Metadata

Release files for qt-css-engine 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qt-css-engine 0.1.7
File Size Uploaded Provenance Actions
qt_css_engine-0.1.7.tar.gz 192.9 kB With provenance Details for qt_css_engine-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qt-css-engine 0.1.7
File Interpreter ABI Platform Actions
qt_css_engine-0.1.7-py3-none-any.whl Python 3 none any Details for qt_css_engine-0.1.7-py3-none-any.whl

Total release size: 279.5 kB

Release files / qt_css_engine-0.1.7.tar.gz

Download URL qt_css_engine-0.1.7.tar.gz
Size 192.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8c6e4214981458ef7ff9a413f4cb3ca2e1f34326609d8cc93c6bf3b9ac3d8d25
BLAKE2b-256 checksum
How to use checksums
45172fff9574f148561f13b6f21375d1a0bd0425059025fbf15dd68a8d2d77c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Release files / qt_css_engine-0.1.7-py3-none-any.whl

Download URL qt_css_engine-0.1.7-py3-none-any.whl
Size 86.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1e7d5ed53202dace067804668acfab1acb7e43a7fd679f505740f3dab7a27c9
BLAKE2b-256 checksum
How to use checksums
b67e79e9f15c2fc4fc884e69b51b3d63c5e6fc1f567cb5aa42fcc359f538a4ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Security for qt-css-engine 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for qt_css_engine-0.1.7.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page