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 moment:
QGLWidget *widget = ui->renderWidget;
QPainter painter;
widget->makeCurrent();
glEnable(GL_MULTISAMPLE);
glEnable(GL_LINE_SMOOTH);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.begin(widget);
However, anything drawn with this painter still has jagged edges. What else do I need to do?
I found the solution. When debugging a different issue, I found messages in my debug output to the effect that you can't set renderhints before the call to begin().
The following works:
QGLWidget *widget = ui->renderWidget;
QPainter painter;
widget->makeCurrent();
glEnable(GL_MULTISAMPLE);
glEnable(GL_LINE_SMOOTH);
painter.begin(widget);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
You can try to enable the antialiasing on the complete Widget :
QGLWidget::setFormat(QGLFormat(QGL::SampleBuffers));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With