QOpenGLWidget's format(smaples) would be reset As QGraphicsView’s viewport
-
I try to enable MSAA in QOpenGLWidget, So I set the format samples as 8. Everything is fine in QGraphicsView's constructor. But MSAA does not work, then I find in drawcall function, format samplels == 0 ! Here are codes;
QGraphicsView's constructor code :auto gl_widget = new SGOpenGLWidget(this); QSurfaceFormat fmt = gl_widget->format(); setViewport(gl_widget); auto view_widget = this->viewport(); QOpenGLWidget* gg_widget = dynamic_cast<QOpenGLWidget*>(view_widget); if (gg_widget) { auto fmt = gg_widget->format(); auto num = fmt.samples(); // num is 8,bacause i set it as deafult format }but at QGraphicsView::drawBackground(QPainter* painter, const QRectF& rect) , code is here:
auto view_widget = this->viewport(); QOpenGLWidget* gl_widget = dynamic_cast<QOpenGLWidget*>(view_widget); if (gl_widget) { auto fmt = gl_widget->format(); auto num = fmt.samples(); // samples num becomes 0! fmt.setSamples(4); gl_widget->setFormat(fmt);// not work auto size = fmt.depthBufferSize(); auto gl_ctx = gl_widget->context(); auto ctx_fmt = gl_ctx->format(); auto ctx_num = ctx_fmt.samples(); }So SMAA does not work at all. Is it a bug in Qt?