我正在尝试在 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/