Skip to content

Who owns the size of a node and its embedded widget? (investigation) #568

Backlog

Description

@paceholder

Your idea

Investigate who owns the size of a node and its embedded widget. Today the widget comes first and the node follows. Decide if the node geometry should come first. Decide it before v4, together with the model-backed groups (#539).

Problem to be solved

Several reports have one root: the node and the widget get their sizes in different places, and nothing keeps them in sync. #189, #392, #408, #433 and #466 are about it.

What the code does today. Everything below was read from the code. None of it is tested yet, unless it says so.

  1. The widget comes first. recomputeSize() in both default geometries builds the node Size from w->width() and w->height() plus the caption, the ports and the spacing.
  2. A manual resize changes the widget. NodeGraphicsObject::mouseMoveEvent calls w->resize(old + diff) and then recomputeSize(). The node follows.
  3. The node Size role can be set, but the next recomputeSize() overwrites it. issue restoring a node's size via load/save JSON #433 had to work around this with BasicGraphicsScene::onNodeUpdated.
  4. NodeDelegateModel::embeddedWidgetSizeUpdated() has no listener in src, include, examples or docs. A comment in Embedded widget with wrong size when content has changed #408 says that emitting it from an event filter helped, so we need to check what really reacts to it.
  5. A widget that changes its own size does not enlarge the node, unless the model emits requestNodeUpdate().
  6. A widget with an expanding vertical size policy gets its minimum height once, from the node size at the time of embedding. The node may then not become smaller than it was at the start.
  7. While dragging the resize handle, Qt limits w->resize() to the minimum and maximum size of the widget. The code adds the mouse movement to the old size each time, so the handle may stop following the cursor.
  8. recomputeSize() reads the widget size before the first layout. We do not know yet if the first node size then differs from the final one.
  9. widgetPosition() added an unsigned caption height to signed sizes. A widget taller than its node was placed about two billion pixels away. This one is reproduced and has a fix under found and solved one small problem, when zooming the image node, especially with the height and width changing at the same time #189.

Prior art

Not collected yet. Qt's own graphics view layouts (QGraphicsLayout) put the geometry of the parent first and hand the children their rectangles. We should check how other node editors do it.

Additional context

Question to answer: what if the geometry came first everywhere? The node Size would be the one stored value. The widget would get the inner rectangle of the node. This could help saved sizes, switching the orientation, and expanding widgets. The open problems: widgets have minimum sizes, widgets with their own layouts, and custom AbstractNodeGeometry classes in user code. This is an idea, not a verified design.

Plan:

  • Write a test for each point above and mark it confirmed or not.
  • Check the behavior in the resizable_images example.
  • Open a separate bug for each confirmed point.
  • Decide the ownership rule for v4.

Related: #189, #392, #408, #433, #466, #545.

Activity

  1. paceholder commented on Dec 2, 2026

    @paceholder
    OwnerAuthor

    Status after #569 and #575, and what the audit found

    Of the nine points above:

    Found by the audit and a prototype:

    • The size is never saved. After a delete and an undo, a node that was resized from 136x84 to 196x124 is back at 136x84. A resize with the handle is not an undo step.
    • A new node writes Size three times. Two scenes on one model overwrite each other's size (scene A drew at height 44 instead of 84).
    • A mouse resize does not set a node size. It resizes the widget, and the node follows. A node without a widget cannot be resized by the mouse.
    • The old text in the advanced guide told models to emit nodeUpdated from setNodeData(Size). This recurses, because the scene writes Size while it handles nodeUpdated. The text is corrected in Add a guide to change notifications and describe the Size role #576.

    Inputs of the size today: the caption, the label, the port count and the port captions, the size of the embedded widget (set by the widget itself, by the delegate, or by the mouse), the processing status, the orientation and the fonts. The recompute runs at node creation, on each nodeUpdated, on setOrientation and from the resize handle.

    The graph is not one-way. The layout size is written back into the model, where anyone can read it as an input. For an expanding widget, the node size also sets the widget's minimum height.

    An option that is one-way: the inputs above, plus an optional requested size (saved, set by the mouse or by code), give the layout size. The layout size gives the bounding rect, the port positions, the widget rectangle, the connections and the group box. The mouse then sets the requested size, and the widget gets its rectangle. Nothing flows back, so a loop cannot happen. nodeUpdated stays a coarse "dirty" mark: some input changed, so recompute once.

    A possible step for 3.x: write the derived Size only when it changed. Then a model that emits from setNodeData(Size) costs one extra pass and not a recursion.

    Open question: should NodeRole::Size mean "the size that the user asked for" only, with the layout size kept in the view (v4)?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions