本文介绍了如何在QGraphicsView中为QOpenGLWidget启用抗锯齿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已通过QGraphicsProxyWidget将QOpenGLWidget添加到QGraphicsView(不使用setviewport):

I have added QOpenGLWidget to QGraphicsView (don't use setviewport) via QGraphicsProxyWidget:

QSurfaceFormat format= QSurfaceFormat();
format->setSamples(4); //<== widget show black screen if samples =4, 1 is ok but not antialiasing
m_glWidget->setFormat(format);

MyGraphicsProxyWidget* proxy= new MyGraphicsProxyWidget();
proxy->setWidget(m_glWidget);
//add to scene
scene->addItem(proxy);

我尝试了一些方法,但是没有用:如果样本= 4,但样本= 1没问题,则glwidget显示黑屏,但不能抗锯齿.那么如何在QGraphicsView中为QOpenGLWidget(由GraphicsproxyWidget添加)启用抗锯齿呢?

I've tried some ways but not work:glwidget show black screen if samples =4, but samples = 1 is ok but not antialiasing.So how to enable antialiasing for QOpenGLWidget (added by GraphicsproxyWidget) in QGraphicsView?

有什么帮助吗?谢谢!

推荐答案

在qapplication初始化下,将代码追加到main.cpp之外

append beyond code to your main.cpp under qapplication initialization

QSurfaceFormat fmt;
fmt.setSamples(10);
QSurfaceFormat::setDefaultFormat(fmt);

这篇关于如何在QGraphicsView中为QOpenGLWidget启用抗锯齿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 20:19