【问题标题】:How to do Antialiasing on Custom QQuickItem with QSGGeometry如何使用 QSGGeometry 对自定义 QQuickItem 进行抗锯齿处理
【发布时间】:2018-08-10 10:27:47
【问题描述】:

我创建了自己的自定义 QQuickItem,它应该使用 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);

如何为这条曲线启用抗锯齿功能?

【问题讨论】:

标签: qt qml qtquick2


【解决方案1】:

试试这个:

QQuickView view;
QSurfaceFormat format = view.format();
format.setSamples(16);
view.setFormat(format);
view->setSource("...");
view.show();

【讨论】:

  • 如果你不使用 QQuickView 而是使用 qml 中的 ApplicationWindow,你会怎么做?那么c++端就只有QQmlApplicationEngine了。
  • 好的,对于 ApplicationWindow,你可以这样做 QQuickWindow* window = (QQuickWindow*) engine.rootObjects().first(); QSurfaceFormat 格式;格式.setSamples(8);窗口->setFormat(格式);但是,有没有办法只针对 QSGNode,而不是针对整个窗口?
猜你喜欢
  • 2021-03-05
  • 2012-12-18
  • 2023-03-20
  • 2010-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多