Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QRadialGradient is pixelated



  • I've been experimenting with QRadialGradient and noticed that the gradient shows up as rectangles (pixelated). I guess this was implemented like this to reduce the intensity of the computation (it looks something like bilinear interpolation or cubic convolution), after all, it is easier to draw rectangles than circles.

    My problem is that this pixelation gets well visible at smaller circles (eg: 80, 80). Is there any way I can reduce this pixelation?
    I've added the code I'm using and the results of the drawing. I've also tried to use QPainter::HighQualityAntialiasing and QPainter::SmoothPixmapTransform, but without much change.

    @ QImage::Format format = QImage::Format_ARGB32;
    QImage buffer(qCeil(width), qCeil(height), format);
    buffer.fill(qRgba(255, 255, 255, 0));

    QPainter painter(&buffer);
    painter.setPen(Qt::NoPen);
    painter.setRenderHint(QPainter::Antialiasing, true);

    QRadialGradient radialGradient(QPointF(width / 2, height /2), qMax(width, height) / 2);
    QColor color = ViThemeManager::color(14);
    color.setAlpha(150);
    radialGradient.setColorAt(1, Qt::transparent);
    radialGradient.setColorAt(0.8, ViThemeManager::color(14));
    radialGradient.setColorAt(0.7, color);
    radialGradient.setColorAt(0, color);

    painter.setBrush(radialGradient);
    painter.drawRect(0, 0, width, height);

    painter.end();@

    !http://visore.org/other/1.png(Image 1)!

    !http://visore.org/other/2.png(Image 2)!


Log in to reply