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. QLabel QPixmap Antialiasing
Qt 6.11 is out! See what's new in the release blog

QLabel QPixmap Antialiasing

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 415 Views 1 Watching
  • 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.
  • G Offline
    G Offline
    great_newbie
    wrote on last edited by great_newbie
    #1

    Hi, Guys!
    I am attempting to draw an image with rounded corners in a QLabel. I have tried using QPainter to draw the image and set the QPainter::Antialiasing property in an effort to eliminate the jagged edges of the corners, but it doesn't seem to be working. Here is my code:

    QPixmap QLabelUtils::pixmapToRound(QPixmap& src, int x, int y, int width, int height, int radius) {
        if (src.isNull()) {
            return QPixmap();
        }
    
        QSize size(width, height);
        QBitmap mask(size);
        QPainter painter(&mask);
        painter.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
        painter.fillRect(x, y, size.width(), size.height(), Qt::white);
        painter.setBrush(QColor(0, 0, 0));
    
        QPainterPath path;
        path.addRoundedRect(x, y, size.width()-1, size.height()-1, radius, radius);
        path.translate(0.5, 0.5);
        painter.drawPath(path);
    
        QPixmap image = src.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
        image.setMask(mask);
        return image;
    }
    

    my Qt version is 6.4.
    Please help me solve this problem, it's really bothering me. Thank you very much.

    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