Suppose that I have several node styles, and I would like to switch between them to indicate a state of a node (perhaps using a distinct backColor). On the level of my qan::Node subclass, I call getItem()->setStyle(x), after which I would expect that the QML code would adapt to my changes. Instead I see no difference.
In my particular case, I am using RectNodeTemplate, which internally relies on RectSolidBackground. By diving deep into the UI code, I found that because of lazy-loading, the node template only assigns the style property when the nodeItem property changes. Furthermore, there are protections against configuring nodeItem to null or undefined, which make it impossible to reset the nodeItem and explicitly set it again as a workaround.
By local experimentation, I figured out that the following patch to src/RectNodeTemplate.qml corrects the issue. It simply adds a change handler to nodeItem.style, which passes on the change to the loaded delegate. You may perhaps want to implement analogous fix to edges and groups.
diff --git a/src/RectNodeTemplate.qml b/src/RectNodeTemplate.qml
index 786380c..2fdf00d 100644
--- a/src/RectNodeTemplate.qml
+++ b/src/RectNodeTemplate.qml
@@ -55,7 +55,12 @@ Item {
delegateLoader.item.nodeItem)
delegateLoader.item.nodeItem = nodeItem
}
+ onStyleChanged: {
+ if (template.nodeItem && delegateLoader.item)
+ delegateLoader.item.style = template.nodeItem ? template.nodeItem.style : undefined
+ }
readonly property real backRadius: nodeItem && nodeItem.style ? nodeItem.style.backRadius : 4.
+ readonly property var style: nodeItem ? nodeItem.style : undefined
Loader {
id: delegateLoader
anchors.fill: parent
Suppose that I have several node styles, and I would like to switch between them to indicate a state of a node (perhaps using a distinct
backColor). On the level of myqan::Nodesubclass, I callgetItem()->setStyle(x), after which I would expect that the QML code would adapt to my changes. Instead I see no difference.In my particular case, I am using
RectNodeTemplate, which internally relies onRectSolidBackground. By diving deep into the UI code, I found that because of lazy-loading, the node template only assigns thestyleproperty when thenodeItemproperty changes. Furthermore, there are protections against configuringnodeItemtonullorundefined, which make it impossible to reset thenodeItemand explicitly set it again as a workaround.By local experimentation, I figured out that the following patch to
src/RectNodeTemplate.qmlcorrects the issue. It simply adds a change handler tonodeItem.style, which passes on the change to the loaded delegate. You may perhaps want to implement analogous fix to edges and groups.