PDA

View Full Version : pixmap to polygon



mhoover
14th October 2009, 08:58
I'm trying to convert a sprite (QGraphicsPixmapItem) to a polygon (QGraphicsPolygonItem).

I know Qt creates some kind of boundary region because when the contains() call accurately returns only when I am actually clicking on the item (after I do the mapToScene() call).

When I try to get the QGraphicsPixmapItem::boundingRegion(QTransform) it crashes. I'm not sure I have the right idea in using this function because why would it accept a transform?

There's also a QGraphicsPixmapItem method that returns a QPolygonF called "mapToScene". But I don't think that's what I want either since you have to pass a polygon to the QGraphicsPixmapItem to get a polygon back. That doesn't seem to quite make sense for what I'm trying to do.

I'd eventually like to create a QGraphicsPolygonItem from the QGraphicsPixmapItem coordinates.

Any ideas?

scascio
14th October 2009, 10:02
I dont really understand whta information in your pixmap you want ot convert into a polygon. Is it the boundingRect() or some shape defined by a mask or from colored pixels?

Anyway, have a look at QPainterPath. This can be the link that fits your needs since this is the return type of QGraphicsItem::opaqueArea and can be constructed with polygons or region