How to enable antialiasing for QOpenGLWidget in QGraphicsView?
Asked Answered
S

1

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!

Spirketing answered 9/2, 2015 at 19:10 Comment(2)
Have you tried view.setRenderHints(QPainter::Antialiasing)?Gilles
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)Spirketing
N
5

append beyond code to your main.cpp under qapplication initialization

QSurfaceFormat fmt;
fmt.setSamples(10); 
QSurfaceFormat::setDefaultFormat(fmt);
Nicolette answered 29/12, 2015 at 12:2 Comment(2)
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.Sexy
Can be required to call explicitely glEnable(GL_MULTISAMPLE); before each drawing. I experimented issues without doing that.Sexy

© 2022 - 2024 — McMap. All rights reserved.