[PyQt] Rounded corners

Alfredo Junior junixrj at yahoo.com
Wed Apr 11 01:13:57 BST 2012


Thank you man.

Works very well! =)



----- Original Message -----
From: Vincent Vande Vyvre <vincent.vandevyvre at swing.be>
To: pyqt at riverbankcomputing.com
Cc: 
Sent: Monday, April 9, 2012 9:45 PM
Subject: Re: [PyQt] Rounded corners

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>

_______________________________________________
PyQt mailing list    PyQt at riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt



More information about the PyQt mailing list