Repository navigation
Description
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.
- The widget comes first.
recomputeSize()in both default geometries builds the nodeSizefromw->width()andw->height()plus the caption, the ports and the spacing. - A manual resize changes the widget.
NodeGraphicsObject::mouseMoveEventcallsw->resize(old + diff)and thenrecomputeSize(). The node follows. - The node
Sizerole can be set, but the nextrecomputeSize()overwrites it. issue restoring a node's size via load/save JSON #433 had to work around this withBasicGraphicsScene::onNodeUpdated. NodeDelegateModel::embeddedWidgetSizeUpdated()has no listener insrc,include,examplesordocs. 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.- A widget that changes its own size does not enlarge the node, unless the model emits
requestNodeUpdate(). - 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.
- 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. 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.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_imagesexample. - Open a separate bug for each confirmed point.
- Decide the ownership rule for v4.
Activity
paceholder commentedon Dec 2, 2026
Status after #569 and #575, and what the audit found
Of the nine points above:
setNodeData(Size)stores the value and emits nothing.embeddedWidgetSizeUpdatedis wired now (Fix the gaps in the change notifications of the scene and the model #575). The model emitsnodeUpdated, like forrequestNodeUpdate.Found by the audit and a prototype:
Sizethree times. Two scenes on one model overwrite each other's size (scene A drew at height 44 instead of 84).nodeUpdatedfromsetNodeData(Size). This recurses, because the scene writesSizewhile it handlesnodeUpdated. 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, onsetOrientationand 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.
nodeUpdatedstays a coarse "dirty" mark: some input changed, so recompute once.A possible step for 3.x: write the derived
Sizeonly when it changed. Then a model that emits fromsetNodeData(Size)costs one extra pass and not a recursion.Open question: should
NodeRole::Sizemean "the size that the user asked for" only, with the layout size kept in the view (v4)?Write the node size only when it changed