I am working on a program in PyQt and creating a widget that displays a grid and a set of polygons on that grid that you are able to move around and click on. When I try to implement the clicking of the polygon, it does not seem to work. Below is the function that does not work:
def mouseMoveCustom(self, e):
for poly in reversed(self.polys):
if poly.contains(e.pos()):
self.cur_poly = poly
self.setCursor(Qt.PointingHandCursor)
print('mouse cursor in polygon')
break
else:
self.setCursor(Qt.CrossCursor)
For context, self.polys
is a list of QPolygons
and e.pos()
is the mouse position. I have tried entering
print(poly)
print(poly.contains(QPoint(1,1)))
to test if it would work for a control point, but in the console, it only gives me this:
<PySide.QtGui.QPolygon(QPoint(50,350) QPoint(50,0) QPoint(0,0) QPoint(0,350) ) at 0x000000000547D608>
False
Is there something I am doing wrong here, or how can I convert the above "polygon" into an actual QPolygon
that I can work with?
EDIT:
This is the code used to generate the list self.polys
:
self.polys.append(QPolygon([QPoint(points[i][X]+self.transform[X], points[i][Y]+self.transform[Y]) for i in range(len(points))]))
Could it perhaps be a problem with using an inline for loop to add the QPolygons
to the list?