7

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!

lemta
  • 211
  • 3
  • 8
  • 1
    Have you tried `view.setRenderHints(QPainter::Antialiasing)`? – Pavel Strakhov Feb 09 '15 at 19:17
  • yes, I've tried before (both of painter in glwidget and graphicsview) but not antialiasing (but still that glwidget if add to QMainwindow and set samples = 4, it works well) – lemta Feb 10 '15 at 01:27

1 Answers1

5

append beyond code to your main.cpp under qapplication initialization

QSurfaceFormat fmt;
fmt.setSamples(10); 
QSurfaceFormat::setDefaultFormat(fmt);
yousong kim
  • 51
  • 1
  • 2
  • 1
    Just as a note, this is required to be BEFORE the widget or its parent are shown: e.g. For QOpenGLWidget, initializeGL is called in the main app.exec() loop, so too late.In my case, I did it in the widget constructor. – Adrian Maire Feb 25 '16 at 11:36
  • 1
    Can be required to call explicitely `glEnable(GL_MULTISAMPLE);` before each drawing. I experimented issues without doing that. – Adrian Maire Aug 08 '16 at 11:40