Skip to content

Draw node shadows without a graphics effect, by default - #544

Merged
paceholder merged 1 commit into
masterfrom
pr-534-clean
Nov 22, 2026
Merged

paceholder merged 1 commit into
masterfrom
pr-534-clean

Conversation

@paceholder

Copy link
Copy Markdown
Owner

Type of change

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

Description

Draw the node shadow in DefaultNodePainter and make this the default.

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 (QTBUG-77400, not fixed). The painted shadow uses no
graphics effect, so the node is drawn completely.

This continues #534 by Doome161. It is one commit with the author kept. On top of that PR it has:

  • Fit the shadow to QGraphicsDropShadowEffect (offset 4, blur 20). I rendered both and fitted
    the layers; the opacity matches within about 4 of 255 at 0 to 24 px from the node edge.
  • Set PaintedShadowEnabled to true in DefaultStyle.json. A style JSON without the key still
    keeps the Qt graphics effect.
  • Docs and a FAQ entry for the Qt bug. Tests are renamed to state their rule.
  • A test that renders a view zoomed in on a node larger than the view. It fails with the Qt
    effect and passes with the painted shadow.

Limits: custom painters have no shadow in this mode and must draw their own. Custom geometries
need a margin of 11 px above and left, and 19 px below and right. 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. The docs say so.

Testing

  • Qt version tested: Qt 6.12.0, macOS (Apple Clang)
  • Existing tests still pass (716 assertions in 62 test cases, offscreen)
  • Added tests for new functionality (if applicable)
  • Not tested: Qt 5, a real GPU, a high DPI screen, image export and printing. The docs were not built.

Breaking changes?

Source compatible. The default look changes slightly (an approximation of the Qt shadow), and
custom painters lose the shadow unless they draw it. NodeStyle gets a new public member, so
shared builds need a rebuild. This is meant for a minor release (3.2.0).

Related issue

Fixes #121
Supersedes #534

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
paceholder merged commit 36687de into master Nov 22, 2026
3 checks passed
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.

Maximum Zoom In causes improper node rendering

2 participants