1

Currently have a program where a user is able to draw their own shape using mouse clicks. It then takes a list of QPointFs (obtainted from user mouse clicks) and creates a QPolygonF. This step is fine and a visible outline of the polygon can be seen when converted to a PolygonItem and added to a graphics view. However I need to convert it to a QImage and set its pixels to green (colour important later when solving the centre of mass) but I'm unsure how to do so. Currently I have...

self.poly=QPolygonF(self.vertexList) #works

self.polyItem=QGraphicsPolygonItem(self.poly) #works, visible when added to scene

self.pixItem=QGraphicsPixmapItem(self.polyItem) #for some reason this step doesn't work. The pixmap item is created, however its empty

self.addItem(self.pixItem) #not visible, this is where it goes wrong

self.pix = self.pixItem.pixmap()

self.image=self.pix.toImage()

self.image.convertToFormat(4)#4=RGB32

value=qRgb(0,255,0) #These last two lines turn it green but irrelevant to issue

self.image.fill(value)

As far as I understand you can convert one type of item to another (no error is given) but with the polygon item to pixmap item it goes blank. Would be grateful for any help.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Alex Zandy
  • 11
  • 1

0 Answers0