qt - 在 QGLWidget 上使用 QPainter 时需要执行哪些步骤才能启用抗锯齿功能?

标签 qt opengl

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

这就是我现在正在尝试的:

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

但是,用该画家绘制的任何东西仍然有锯齿状边缘。我还需要做什么?

最佳答案

我找到了解决方案。在调试另一个问题时,我在调试输出中发现了一些消息,大意是您无法在调用 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);

关于qt - 在 QGLWidget 上使用 QPainter 时需要执行哪些步骤才能启用抗锯齿功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10971428/

相关文章:

java - If Else 语句导致 stage 行为 GLSL

c++ - 图形硬件上的最近邻搜索

c++ - 无法在 OpenGL 上使用不同的 VAO 渲染不同的网格

c++ - doLayout : how to setGeometry on top of another widget?

python - 在 OpenGL 中围绕中心点旋转四边形

qt - 如何覆盖 Q_Property?

c++ - 我无法将 KAction 连接到 KMainWindow 上的插槽

python - python 中的 SVG 与 cairo、opengl 和 rsvg 的交互

c++ - QtMainWindow 初始化事件

qt - 当 QTableWidget 中有一项时,如何防止标题被选中?