What steps are necessary to enable antialiasing when using a QPainter on a QGLWidget?

前端 未结 4 1886
情深已故
情深已故 2020-12-10 03:43

I am trying to draw basic shapes on a QGLWidget. I am trying to enable antialiasing to smooth out the lines, but it is not working.

This is what I am trying at the m

4条回答
  •  北海茫月
    2020-12-10 04:20

    This question is quite old but I still found it on Google. You shouldn't use QGLWidget any more. Use the newer QOpenGLWidget. This renders the scene off-screen rather than creating a native OpenGL window which causes all sorts of issues with resizing layouts. This code works for me. Put it in your QGraphicsView constructor:

    QOpenGLWidget* gl = new QOpenGLWidget;
    QSurfaceFormat fmt;
    fmt.setSamples(8);
    gl->setFormat(fmt);
    setViewport(gl);
    setRenderHint(QPainter::Antialiasing);
    

提交回复
热议问题