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
  • 449,505
  • 63
  • 781
  • 982
numberCruncher
  • 595
  • 1
  • 6
  • 25
  • 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

2

Try this:

QQuickView view;
QSurfaceFormat format = view.format();
format.setSamples(16);
view.setFormat(format);
view->setSource("...");
view.show();
folibis
  • 12,048
  • 6
  • 54
  • 97
  • 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