di_zou
2nd July 2010, 15:25
I have a widget with a QTreeView, QGraphicsScene, and a QGraphicsView:
MainWidget.py:
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:
class DisplayItem(QGraphicsPixmapItem):
def __init__(self, parent, pixmap=None, graphView=None):
if pixmap:
self.HasPixmap = True
QGraphicsPixmapItem.__init__(self, pixmap)
self.setAcceptHoverEvents(True)
self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable)
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?
MainWidget.py:
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:
class DisplayItem(QGraphicsPixmapItem):
def __init__(self, parent, pixmap=None, graphView=None):
if pixmap:
self.HasPixmap = True
QGraphicsPixmapItem.__init__(self, pixmap)
self.setAcceptHoverEvents(True)
self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable)
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?