cpp
QPixmap roundedPixmap(const QPixmap& src, QSize size, int radius) {
QPixmap scaled = src.scaled(size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
QPixmap dest(size);
dest.fill(Qt::transparent);
QPainter painter(&dest);
painter.setRenderHint(QPainter::Antialiasing);
QPainterPath path;
path.addRoundedRect(0, 0, size.width(), size.height(), radius, radius);
painter.setClipPath(path);
painter.drawPixmap(0, 0, scaled);
return dest;
}
QPixmap rounded = roundedPixmap(QPixmap("xxx.jpg"), ui->portrait_label->size(), 20); // 设置圆角半径
ui->portrait_label->setPixmap(rounded);