[Interest] Custom QQuickItem with smooth painting
Gunnar Sletta
gunnar at sletta.org
Tue Jan 27 08:22:11 CET 2015
You can either rely on multisample antialiasing by doing:
QQuickView view;
QSurfaceFormat format = view.requestedFormat();
format.setSamples(16); // set as high as possible, will be cut back to what is supported
view.setFormat(view);
view.setSource(“my.qml”);
view.show();
By requesting a multisampled OpenGL context, all primitives will be antialiased. Depending on your hardware, this might come at a performance cost though.
If you don’t want to rely on multisampling, you need to create triangles along the edges of your line to “fake” an antialiased edge, like you already found out that the default rectangle implementation does.
-
cheers,
Gunnar
> On 27 Jan 2015, at 02:49, Ruslan Moukhlynin <ruslan at khvmntk.ru> wrote:
>
> Hi all!
> In my app I use some custom QML element, for simplicity it just a line.
>
> So I overrided QQuickItem::updatePaintNode and inside it I paint my element.
>
> QSGGeometry *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 2);
> geometry->setDrawingMode(GL_LINES);
> geometry->setLineWidth(3);
> geometry->vertexDataAsPoint2D()[0].set(0, 0);
> geometry->vertexDataAsPoint2D()[1].set(width(), height());
>
> QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
> material->setColor(QColor(255, 0, 0));
>
> QSGGeometryNode *node = new QSGGeometryNode;
> node->setGeometry(geometry);
> node->setFlag(QSGNode::OwnsGeometry);
> node->setMaterial(material);
> node->setFlag(QSGNode::OwnsMaterial);
>
> But this line looks so ugly. There is no antialiasing at all here.
> Ok, I 've looked through QSGDefaultRectangleNode source from $QTDIR/Src/qtdeclarative/src/quick/scenegraph and tried to implement its QSGSmoothColorMaterial instead of QSGFlatColorMaterial but nothing works, I just get segmentation fault.
> I can't see call stack, just some assembler code so I cannot find the problem line in my code.
>
> So my question is very simple - how can I paint smooth line in custom QQuickItem item? Any advice, example or suggestions will be greatly appreciated!
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150127/3edca497/attachment.html>
More information about the Interest
mailing list