c++ - 如何在视网膜显示器上使用 QPainter、QOpenGLPaintDevice 和 QOpenGLWidget 平滑绘制?
问题描述
当我尝试使用QWidget
和绘图时,绘图非常滞后QPainter
。我决定使用QOpenGLPaintDevice
and来加速绘图QOpenGLWidget
。但是与在常规小部件上绘制相比,形状的圆角非常粗鲁。
QWidget:
QOpenGL小部件:
这是我如何设置 QOpenGLPaintDevice 的代码。
QOpenGLPaintDevice* device = nullptr;
void QOpenGLWorkspaceWidget::resizeGL(int w, int h) {
initDeviceIfNeed();
handleResize(this, w, h);
int ratio = devicePixelRatio();
device->setSize(QSize(w * ratio, h * ratio));
device->setDevicePixelRatio(ratio);
}
void QOpenGLWorkspaceWidget::initDeviceIfNeed() {
if (!device) {
device = new QOpenGLPaintDevice();
drawer->setPaintDevice(device);
}
}
void QOpenGLWorkspaceWidget::paintGL() {
initDeviceIfNeed();
glDisable(GL_DEPTH_TEST);
glClearColor(1, 1, 1, 1);
workspaceDrawer->draw();
}
解决方案
我在这里找到了答案
在 QGLWidget 上使用 QPainter 时启用抗锯齿需要哪些步骤?
openGlWidget.setSamples(8)
并painter.setRenderHint(QPainter::Antialiasing)
完成了这项工作。
推荐阅读
- kotlin - Kodein 构造函数注入 Kodein$NotFoundException
- node.js - 通过 Node AWS SDK 的 lambda.invoke 调用在 5 分钟时超时,而 Lambda 在 4 分钟内完成
- python - 使用贪心python算法解决背包问题
- node.js - 如何使用正文解析器在 Express.js 中读取 BSON 数据
- python - 如何在python中添加对箭头键的反应?
- android - 如何将基于 NFC 的会员卡添加到 Google Pay?
- sql - 通过将行转换为列的 Oracle SQL 查询输出
- php - 如何使用 DATA ATTRIBUTE 将背景图像添加到带有 HTML 和 CSS 的锚标记
- ios - 必须按两次相同的按钮才能调用函数 Swift 4
- reactjs - 使用 ReactStrap 水平对齐卡片