Search code examples
qtqpainterqpixmap

How to draw a QPixmap with rounded corners?


I have inherited from QGraphicsPolygonItem and would like to draw a QPixmap on the top of the item. The item itself and the pixmap should be drawn with rounded corners.

How would you this?


Solution

  • If you want to draw QPixmap with rounded corners then inside of paint event create QBrush from QPixmap and apply it to the painter like that:

    painter->setRenderHint(QPainter::Antialiasing, true);
    QBrush brush = QBrush(pixmap);
    painter->setBrush(brush);
    painter->drawRoundedRect(polygon().boundingRect(), 5, 5);