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