Important: Please read the Qt Code of Conduct -

Custom QQuickItem: Updating Geometry

  • Hi,

    I have a custom QQuickItem which I use to display a x,y graph coming from a measurement device. If the measurement device delivers new data, I need to reset the QSGGeometry. I wonder whether it is possible to only append points to the end of the geometry instead of resetting it completely.

  • Isn't QSGGeometry::allocate is what you need?

  • Maybe :-). I tried it, but sometimes I receive a segfault. I should note that I guess I did not follow this rule:
    "The rule of thumb is to only use classes with the "QSG" prefix inside the QQuickItem::updatePaintNode() function." from
    So I guess the problem is that I might not call it in the right place
    My approach:

    The geometry is a member of the class.

    class PlotCurve : public QQuickItem {
      void updateGeometry(const std::vector<double>* xdata, const std::vector<double>* ydata);
      QSGGeometry * _geometry;
      QSGGeometryNode * _curve;

    When I had static x and y data, I set it in the constructor like this:

     _geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(),xdata->size());
      QSGGeometry::Point2D *points = _geometry->vertexDataAsPoint2D();
      for(int i=0;i<xdata->size();i++) {
        points[i].x = xdata->at(i);
        points[i].y = view_y_range-ydata->at(i)+_view_y_min;

    Here is my updateGeoemtry function

    QSGGeometry::Point2D *points = _geometry->vertexDataAsPoint2D();
    for(int i=0;i<xdata->size();i++) {
      points[i].x = xdata->at(i);
      points[i].y = (_view_y_max-_view_y_min)-ydata->at(i)+_view_y_min;

    and here my updatePaintNode

    QSGNode *PlotCurve::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) {
      QSGNode * mainNode = oldNode;
      if(!mainNode) {
        mainNode = new QSGNode;
      if(!_transformNode) {
        _transformNode = new QSGTransformNode;
      if(!_curve) {
        _curve = new QSGGeometryNode;
        QSGFlatColorMaterial* material = new QSGFlatColorMaterial;
      double transX = -_view_x_min;
      double transY = -(_view_y_max_init-_view_y_max);
      QMatrix4x4 m;
      m.translate(transX, transY);
      return mainNode;

  • So what is the correct way to update the geometry of a QQuickItem? In my case, the xdata and ydata vectors would simply grow with time and the data before would remain the same

  • No one is creating his own QQuickItems with changing geometry?

Log in to reply