How to disable update on a QQuickItem

571 views Asked by At

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?

1

There are 1 answers

2
dtech On BEST ANSWER

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;
}