在 QGLWidget 上使用 QPainter 时,启用抗锯齿需要哪些步骤? [英] What steps are necessary to enable antialiasing when using a QPainter on a QGLWidget?

查看:62
本文介绍了在 QGLWidget 上使用 QPainter 时,启用抗锯齿需要哪些步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 QGLWidget 上绘制基本形状.我正在尝试启用抗锯齿来平滑线条,但它不起作用.

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?

推荐答案

我找到了解决方案.在调试不同的问题时,我在调试输出中发现消息,大意是在调用 begin() 之前不能设置渲染提示.

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().

以下工作:

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);

这篇关于在 QGLWidget 上使用 QPainter 时,启用抗锯齿需要哪些步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆