How to enable antialiasing for QOpenGLWidget in QGraphicsView?

拈花ヽ惹草 提交于 2019-12-07 02:39:46

问题


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);

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?

Any helps? Thanks!


回答1:


append beyond code to your main.cpp under qapplication initialization

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


来源:https://stackoverflow.com/questions/28417423/how-to-enable-antialiasing-for-qopenglwidget-in-qgraphicsview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!