0

I have a QQuickItem derived class

// Class
class MyQQuickItem : public QQuickItem {
  Q_OBJECT
}

// updatePaintNode in cpp function
QSGNode * MyQQuickItem::updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData) {

  // draw UI logic
  return node;
}

// QML component
MyQQuickItem {
  id: my_quick
  objectName: "myquickitem"
  width : 500
  height : 500
}

I am doing something on a separate UI which causes the updatePaintNode of MyQQuickItem to be fired. If I have a pointer to MyQQuickItem on cpp side like so,

QQuickItem * my_quick_item_ptr = m_qml_engine->rootObjects()[0]->findChild<QQuickItem*>("myquickitem");

How can disable MyQQuickItem's updatePaintNode from getting called when I don't want it to?
Secondary question: If yes, How to reinstate it back again?

TheWaterProgrammer
  • 7,055
  • 12
  • 70
  • 159

1 Answers1

1

If and when updatePaintNode() is called is most likely scenegraph internal stuff that wasn't really intended to be modified.

Maybe try doing something less invasive like:

QSGNode * MyQQuickItem::updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData) {
  if (doNotUpdate) return oldNode; 
  // draw UI logic
  return node;
}
dtech
  • 47,916
  • 17
  • 112
  • 190
  • is there something in the `QQuickItem` class to do this? rather than using my own `doNotUpdate` based flag management? – TheWaterProgrammer Sep 07 '17 at 12:26
  • I doubt it will have flags to facilitate non-existent functionality ;) It's just one extra property, which you might as well do since you are extending the class anyway. There is a chance this might not work as expected, I just gave it as an idea, go ahead and try it and report the result, so I can delete the answer if it is no good. – dtech Sep 07 '17 at 12:37