【问题标题】:How to draw smoothly using QPainter, QOpenGLPaintDevice and QOpenGLWidget on retina display? [duplicate]如何在视网膜显示器上使用 QPainter、QOpenGLPaintDevice 和 QOpenGLWidget 平滑绘制? [复制]
【发布时间】:2018-08-24 22:51:57
【问题描述】:

当我尝试使用QWidgetQPainter 绘图时,绘图非常滞后。我决定使用QOpenGLPaintDeviceQOpenGLWidget 来加速绘图。但是形状的圆角与在常规小部件上绘制相比非常粗鲁。

QWidget:

QOpenGLWidget:

这是我如何设置 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();
}

【问题讨论】:

    标签: c++ qt opengl qpainter


    【解决方案1】:

    我在这里找到了答案

    What steps are necessary to enable antialiasing when using a QPainter on a QGLWidget?

    openGlWidget.setSamples(8)painter.setRenderHint(QPainter::Antialiasing) 完成了这项工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-14
      • 1970-01-01
      相关资源
      最近更新 更多