paceholder/nodeeditor

Widget with label: size issue after text update

yvanblanchard opened this issue · 3 comments

Hello,

I have an embedded widget in a custom node, containing a layout and a frame with text.
When initializing the widgets, the frame size is OK (fully inside node):
image

But when updating the text of the label (after clicking on it, through code in click event), the size is KO (label is out of node perimeter):
image

Thank you for your help..

Trzeth commented

Hi yvanblanchard, i figure it out and find quite easy.

If you're using deafult DataFlowGraphModel and DataFlowGraphicsScene like me, everything is almost ok.
This work is based on main brach commit 5465ddc

What you need to do is:

  1. add a Q_SIGNALS in DataFlowGraphModel.hpp named void embeddedWidgetSizeUpdated(NodeId const);
  2. connect this in DataFlowGraphModel.cpp in DataFlowGraphModel::addNode(QString const nodeType) function with connect(model.get(),&NodeDelegateModel::embeddedWidgetSizeUpdated,this,[newId, this](){Q_EMIT embeddedWidgetSizeUpdated(newId);});
  3. PS: You will see lots of connect method there, you can't miss it. ;)
  4. last step is connect this in DataFlowGraphicsScene.cpp in the constructor with connect(&_graphModel,&DataFlowGraphModel::embeddedWidgetSizeUpdated,[this](NodeId const nodeId){ onNodeUpdated(nodeId); });
  5. now you can use this->embeddedWidgetSizeUpdated(); in your DataModel everytime you change label size.

DataFlowGraphModel.hpp

Q_SIGNALS:
     void inPortDataWasSet(NodeId const,PortType const,PortIndex const);
     +void outPortDataUpdated(NodeId const)

DataFlowGraphModel.cpp

void DataFlowGraphModel::onOutPortDataUpdated(NodeId const nodeId)
{
      +Q_EMIT outPortDataUpdated(nodeId);
      ...
}

DataFlowGraphicsScene.cpp

+connect(&_graphModel,
             +&DataFlowGraphModel::outPortDataUpdated,
             +[this](NodeId const nodeId) { onNodeUpdated(nodeId); });

Thank you