1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include <QPixmap> #include <QPainter> #include <QSize> #include <QBitmap> #include <QPainterPath>
Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { ui->setupUi(this);
ui->label->setStyleSheet("background-color:transparent;" "border: 1px solid rgba(0,0,0,1);" "border-radius: 8px;");
int w = ui->label->width() - 2; int h = ui->label->height() - 2;
QPixmap pixmapback("://images/test.jpeg"); QPixmap pixmap(w,h); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); QPainterPath path; path.addRoundedRect(0, 0, w, h,8,8); painter.setClipPath(path); painter.drawPixmap(0, 0, w, h, pixmapback);
ui->label->setPixmap(pixmap); }
|