[Interest] Custom QQuickItem with smooth painting

Ruslan Moukhlynin ruslan at khvmntk.ru
Wed Jan 28 00:33:00 CET 2015


Thanks for the answer!

In my case setting samples makes the output even worse then without 
setting it. I've tried 16 and 255, nothing works.

Setting format.setSamples() removes any antialiasing at all.

Without format.setSamples() - http://pbrd.co/1EO9GRh


With format.setSamples() - http://pbrd.co/1EO9KjX

The yellow star is my shape I want to paint with antialiasing. The 
rectangle is QML Rectangle with radius set.



27.01.2015 17:22, Gunnar Sletta пишет:
> 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 
>> <mailto: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 <mailto: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/20150128/2d47d5fa/attachment.html>


More information about the Interest mailing list