Important: Please read the 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.setRenderHint(QPainter::Antialiasing, true);

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

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


    ! 1)!

    ! 2)!

Log in to reply