Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable antialiasing for QOpenGLWidget in QGraphicsView?

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!

like image 539
lemta Avatar asked Feb 09 '15 19:02

lemta


1 Answers

append beyond code to your main.cpp under qapplication initialization

QSurfaceFormat fmt;
fmt.setSamples(10); 
QSurfaceFormat::setDefaultFormat(fmt);
like image 174
yousong kim Avatar answered Sep 24 '22 09:09

yousong kim