Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. QLabel锯齿设置Antialiasing无效,求解决
Forum Updated to NodeBB v4.3 + New Features

QLabel锯齿设置Antialiasing无效,求解决

Scheduled Pinned Locked Moved Unsolved Chinese
1 Posts 1 Posters 575 Views
  • 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
    #1

    有人来帮忙看看吗?这个问题怎么解决?我想在QLabel上加载图片,并且设置为圆角,设置圆角成功了,但是锯齿严重,下面是我的代码,哪位大神帮忙看看,谢谢了

    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;
    }
    

    我的Qt版本是6.4。
    太折磨人了,烦请大神们帮忙看看。

    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