Skip to content

Add opt-in lightweight node shadows - #534

Closed
Doome161 wants to merge 9 commits into
paceholder:masterfrom
Doome161:feature/opt-in-lightweight-shadows
Closed

Doome161 wants to merge 9 commits into
paceholder:masterfrom
Doome161:feature/opt-in-lightweight-shadows

Conversation

@Doome161

@Doome161 Doome161 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation/refactoring

Description

This PR introduces optional lightweight node shadows as a performance-oriented alternative to QGraphicsDropShadowEffect.

The existing shadow implementation can be expensive when rendering multiple nodes, particularly during interactive operations such as dragging and zooming.

The new implementation draws a soft shadow approximation directly in DefaultNodePainter using translucent rounded rectangles, avoiding the overhead of a separate graphics effect.

Changes

  • Introduced NodeStyle::FastShadowEnabled (default: false).
  • Added JSON serialization and deserialization for the new setting.
  • Updated NodeGraphicsObject to skip QGraphicsDropShadowEffect when lightweight shadows are enabled.
  • Implemented lightweight shadow rendering in DefaultNodePainter.
  • Added regression tests and documentation.

Usage

Enable lightweight shadows through NodeStyle:

QtNodes::NodeStyle style;
style.ShadowEnabled = true;
style.FastShadowEnabled = true;

Compatibility

The feature is strictly opt-in. Existing applications retain their current rendering behavior without modifications.

Trade-offs:

  • The lightweight shadows are an approximation and are not pixel-identical to Qt's drop-shadow effect.
  • Custom node painters must provide their own shadow rendering when this option is enabled.
  • No global caching behavior or embedded-widget cache modes are modified.

Testing

  • Qt version tested: Not independently verified for this PR submission.
  • Existing tests still pass
  • Added tests for new functionality (if applicable)

Added TestFastNodeShadows.cpp, covering:

  • Default behavior and backward compatibility with existing style configurations.
  • JSON serialization and deserialization.
  • Correct selection between traditional and lightweight shadows.
  • Shadow geometry and rendering boundaries.

Note: The regression tests have been implemented but have not yet been independently executed and verified. Performance benchmarks and visual testing across different zoom levels and DPI settings are also recommended.

Breaking changes?

No breaking changes are intended.

The new FastShadowEnabled property defaults to false, preserving existing behavior and visual appearance.

Related issue

Related to #121 — Maximum Zoom In causes improper node rendering.

This PR provides an optional alternative to the existing graphics effect. It does not claim to resolve the underlying Qt caching issue (QTBUG-77400).

The existing workaround using ShadowEnabled = false remains available.

@Doome161
Doome161 marked this pull request as draft October 25, 2026 19:31
@Doome161
Doome161 marked this pull request as ready for review October 25, 2026 19:50
@paceholder

Copy link
Copy Markdown
Owner

Thank you for this. It is a good fix for the Qt crop bug (QTBUG-77400, #121).

I squashed it into one commit and kept you as the author. It is now in #544. On top of your change I fitted the look to the Qt shadow (offset 4, blur 20), turned it on by default, renamed the option to PaintedShadowEnabled, and added a test that zooms in on a node larger than the view.

One note: I could not confirm a performance gain. On macOS (Apple M1, Qt 6.12) the repaint time is about the same as with the Qt effect, and higher with many overlapping nodes. The approach still fixes the Qt bug, so it should be merged. The docs say this.

Closing as superseded by #544.

@paceholder paceholder closed this Nov 22, 2026
paceholder pushed a commit that referenced this pull request Nov 22, 2026
The Qt drop shadow effect together with the node pixmap cache crops a
node that is larger than the view when the view is zoomed in. This is
QTBUG-77400 and Qt has not fixed it. It was reported as
#121 in 2017.

The bug came back. b56a7d0 added ShadowEnabled and turned the shadow
off by default, which avoided the cropping. 571499b turned it on again
by default, so the cropping returned for all nodes.

Doome161 proposed a shadow that needs no graphics effect in
#534. This commit is based on that proposal.
DefaultNodePainter draws the shadow from translucent rounded rectangles.
The layers are fitted to QGraphicsDropShadowEffect with offset 4 and
blur radius 20. The opacity matches within about 4 of 255 at 0 to 24 px
from the node edge. NodeGraphicsObject creates no graphics effect in
this mode.

NodeStyle::PaintedShadowEnabled switches the mode. It is true in
DefaultStyle.json. A style JSON without the key reads as false and keeps
the graphics effect. Custom painters have no shadow in this mode and
must draw their own, or set the key to false. The custom_painter example
does that. The shadow reaches 11 px above and left, and 19 px
below and right, so it fits the 20 px margins of the default geometries.

Performance was not confirmed. On macOS (Apple M1, Qt 6.12) the repaint
time is about the same as with the Qt effect, and higher with many
overlapping nodes. The change is made for the crop fix, not for speed.

The tests cover the default, the JSON round trip, the choice of mode,
the footprint and the drawing. One test zooms in on a node larger than
the view and checks that the node is drawn completely. It fails with the
graphics effect. The docs and the FAQ describe the mode and the Qt bug.

Fixes #121
paceholder pushed a commit that referenced this pull request Nov 22, 2026
The Qt drop shadow effect together with the node pixmap cache crops a
node that is larger than the view when the view is zoomed in. This is
QTBUG-77400 and Qt has not fixed it. It was reported as
#121 in 2017.

The bug came back. b56a7d0 added ShadowEnabled and turned the shadow
off by default, which avoided the cropping. 571499b turned it on again
by default, so the cropping returned for all nodes.

Doome161 proposed a shadow that needs no graphics effect in
#534. This commit is based on that proposal.
DefaultNodePainter draws the shadow from translucent rounded rectangles.
The layers are fitted to QGraphicsDropShadowEffect with offset 4 and
blur radius 20. The opacity matches within about 4 of 255 at 0 to 24 px
from the node edge. NodeGraphicsObject creates no graphics effect in
this mode.

NodeStyle::PaintedShadowEnabled switches the mode. It is true in
DefaultStyle.json. A style JSON without the key reads as false and keeps
the graphics effect. Custom painters have no shadow in this mode and
must draw their own, or set the key to false. The custom_painter example
does that. The shadow reaches 11 px above and left, and 19 px
below and right, so it fits the 20 px margins of the default geometries.

Performance was not confirmed. On macOS (Apple M1, Qt 6.12) the repaint
time is about the same as with the Qt effect, and higher with many
overlapping nodes. The change is made for the crop fix, not for speed.

The tests cover the default, the JSON round trip, the choice of mode,
the footprint and the drawing. One test zooms in on a node larger than
the view and checks that the node is drawn completely. It fails with the
graphics effect. The docs and the FAQ describe the mode and the Qt bug.

Fixes #121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants