[PyQt] Rounded corners

Vincent Vande Vyvre vincent.vandevyvre at swing.be
Tue Apr 10 01:45:36 BST 2012


Le 09/04/12 20:24, Alfredo Junior a écrit :
> Hi people,
>
> I'm trying to convert some QGraphicsView pictures. The conversion was to round the corners of the image.
>
> I tried to make it on three forms below and do not succeed in any of them.
>
> http://pastebin.com/CwnxpueK
>
>
> I supose that the best way is using setMask(), but I could not do something that works.
>
>
> Thanks.
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
Hi,

You don't need QLabel for that, instead, place your image as texture
into a QBush and fill a QPainterPath with it.

something like that
------------------------------------------------------------------
color = QColor(0, 0, 0, 0)
pix = QPixmap(QSize(width, height))
pix.fill(color)

rect = QRectF(0.0, 0.0, width, height)
painter = QPainter()
painter.begin(pix)
painter.setRenderHints(QPainter.Antialiasing, True)
path = QPainterPath()
path.addRoundedRect(rect, 5.0, 5.0)
painter.drawPath(path)

brush = QtGui.QBrush()
brush.setTexture(QtGui.QPixmap('path/of/image'))

painter.fillPath(path, brush)
painter.end()

pixItem = QtGui.QGraphicsPixmapItem(pix)
---------------------------------------------------------------------

Adjust 'width, height' of course.

-- 
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte+7
<https://launchpad.net/qarte+7> . PaQager <https://launchpad.net/paqager>



More information about the PyQt mailing list