Getting stuck in an infinite loop in QGraphicsPixmapItem::boundingRect()[SOLVED]
I have a widget with a QTreeView, QGraphicsScene, and a QGraphicsView:
MainWidget.py:
Code:
class MainWidget(ControlWidget):
def __init__(self, parent):
ControlWidget.__init__(self, parent)
self.tree = TreeArea(self) #TreeArea inherits QTreeView
self.display = DisplayScene(self) #DisplayScene inherits QGraphicsScene
self.view = DisplayView(self.display) #DisplayView inherits QGraphicsView
self.view.show()
#code to set up layout
def Open(self):
fileName
= QFileDialog.
getOpenFileName(self,
"Open File",
QDir.
currentPath(),
"(*.xml *.xmf *.xmn)")
The QGraphicsScene contains a bunch of QGraphicsPixmapItems in it. The QGraphicsView displays them on the screen. When I click a "Open" button, I enter into the Open() function in my widget. When this happens, I go into an infinite loop where python will continuously go through each QGraphicsPixmapItem's boundingRect() function.
Here is my class that inherits QGraphicsPixmapItem:
Code:
def __init__(self, parent, pixmap=None, graphView=None):
if pixmap:
self.HasPixmap = True
self.setAcceptHoverEvents(True)
self.setZValue(1)
self.setOffset(-9, -9)
def boundingRect(self):
adjust = 2.0
return QRectF(-10 - adjust,
-10 - adjust,
23 + adjust,
23 + adjust
)
I went through the program with a debugger, and I ended up in the boundingRect() function. I go into the boundingRect() function right as I execute the "fileName = QFileDialog.getOpenFileName" command. Also, if I don't set the pixmaps on the QGraphicsPixmapItems, I don't have this problem. This only happens when the QGraphicsPixmapItems have a pixmap. So what is going on?