Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Artefact on upper rounded corner of image
QtWS25 Last Chance

Artefact on upper rounded corner of image

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 94 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    loginmen
    wrote on last edited by
    #1

    alt text
    I draw alpha background on empty image with rounded corners. After draw small images with CompositionMode_SourceIn, but this do and with images created from fill rect.
    I am using qt 6.1.2 and was trying 5.15.2, result are same
    code to reproduce

    #include <QPainter>
    #include <QPainterPath>
    
    void drawAlpha(QImage &image, int width, int height);
    void drawSimple(QVector<QImage> &images, QImage &im, int width, int height);
    void createImage(QVector<QImage> &images, int width, int height);
    
    int main(int , char **) {
        QVector<QImage> images{};
        createImage(images, 96, 96);
        drawSimple(images, images[0], 220, 285);
        drawSimple(images, images[0], 300, 150);
        images[1].save("../test1.png", "PNG");
        images[2].save("../test2.png", "PNG");
        return 0;
    }
    
    
    void drawAlpha(QImage &image, int width, int height) {
        QPainter paint{ &image };
        paint.setRenderHint(QPainter::Antialiasing);
        paint.setPen(Qt::NoPen);
        paint.fillRect(0, 0, width, height, Qt::transparent);
        QPainterPath path{};
        path.addRoundedRect(0, 0, width,  height, 25, 25);
        paint.fillPath(path, Qt::red);
        paint.end();
    }
    
    void drawSimple(QVector<QImage> &images, QImage &im, int width, int height) {
        QImage img{width, height, QImage::Format_RGBA8888};
        drawAlpha(img, width, height);
        QPainter paint{ &img };
        paint.setRenderHint(QPainter::Antialiasing);
        paint.setCompositionMode(QPainter::CompositionMode_SourceIn);
        for (int y = 0; y < height; y += im.height()) {
            for (int x = 0; x < width; x += im.width()) {
                paint.drawImage(x, y, im);
            }
        }
        paint.end();
        images.append(img);
    }
    
    void createImage(QVector<QImage> &images, int width, int height) {
        QImage image { width, height, QImage::Format_RGB888 };
        QPainter paint{ &image };
        paint.fillRect(0, 0, image.width(), image.height(), Qt::black);
        paint.end();
        images.append(image);
    }
    
    1 Reply Last reply
    0
    • L Offline
      L Offline
      loginmen
      wrote on last edited by
      #2

      helped filling image after creation

      img.fill(Qt::transparent);
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved