Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how give smooth transmision to avatar image



  • hi,,,
    this is thecode i added
    ...................................

    QPixmap pix;
    pix.load("C:/Users/inno/Desktop/smile.jpg");
    pix.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
    ui->pushButton->setIcon(QIcon(pix));

    ui->pushButton->setFixedHeight(90);
    ui->pushButton->setFixedWidth(90);
    

    QRect rect(0,0,90,90);
    QRegion region(rect, QRegion::Ellipse);
    ui->pushButton->setMask(region);

    please help me....


  • Lifetime Qt Champion

    Hi
    its unclear what you try
    pix.scaled(width(), height(), << what are those sizes , its not push button.

    so you try to take image and clip it to round avatar image , much like here at Qt forum ?

    Like here
    https://stackoverflow.com/questions/48474941/circle-user-avatar-issue


  • Moderators

    if you actually wan‘t a fadeIn/fadeOut transition of 2 pixmaps, i believe you can do that via QProppertyAnimations that targets the opacity as Property



  • thanks for your reply problem is sloved

    QPixmap pix;
    pix.loadFromData(image_data);
    int size = qMax(pix.width(), pix.height());
    QPixmap rounded = QPixmap(size, size);
    rounded.fill(Qt::transparent);
    QPainterPath path;
    path.addEllipse(rounded.rect());
    QPainter painter(&rounded);
    painter.setClipPath(path);
    painter.fillRect(rounded.rect(), Qt::black);
    int x = qAbs(pix.width() - size) / 2;
    int y = qAbs(pix.height() - size) / 2;
    painter.drawPixmap(x, y, pix.width(), pix.height(), pix);
    ui->pushButton_4->setIcon(QIcon(rounded));


Log in to reply