0

I created my own Custom QQuickItem which should draw a curve using QSGGeometry:

curve = new QSGGeometryNode;
curve->setFlag(QSGNode::OwnsMaterial,true);
curve->setFlag(QSGNode::OwnsGeometry,true);
curve->setGeometry(_geometry);

_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[i];
    points[i].y = _ydata[i];
}
_geometry->setLineWidth(2);
_geometry->setDrawingMode(GL_LINE_STRIP);
curve->setGeometry(_geometry);

How can I enable Anti-Aliasing for this curve?

Nicol Bolas
  • 413,367
  • 61
  • 711
  • 904
numberCruncher
  • 565
  • 1
  • 6
  • 19
  • 1
    This might answer your question as well: https://stackoverflow.com/questions/48895449/how-do-i-enable-antialiasing-on-qml-shapes/ – Tobias Gurdan Jun 12 '19 at 12:20

1 Answers1

1

Try this:

QQuickView view;
QSurfaceFormat format = view.format();
format.setSamples(16);
view.setFormat(format);
view->setSource("...");
view.show();
folibis
  • 11,116
  • 5
  • 47
  • 87
  • 1
    How would you do this if you don't use a QQuickView but the ApplicationWindow in qml? Then you only have the QQmlApplicationEngine on the c++ side. – numberCruncher Mar 28 '18 at 11:28
  • Ok, for the ApplicationWindow you can do it like this QQuickWindow* window = (QQuickWindow*) engine.rootObjects().first(); QSurfaceFormat format; format.setSamples(8); window->setFormat(format); However, is there a way to do it only for the QSGNode, and not for the whole window? – numberCruncher Mar 28 '18 at 12:15