[PyQt] A problem with co-ordinates of a moving item in an
simon.hibbs at gmail.com
Thu Jun 4 18:30:34 BST 2009
I've been playing with the diagramscene demo, which is a great way to learn
about QDiagramScene, and found some odd behaviour which a search of the
archives doesn't illuminate. It's easy to recreate with minor changes to the
original demo code.
The following line (355) in the MainWindow constructor sets the size of the
scene.setSceneRect(QtCore.QRectF(0, 0, 5000, 5000))
Commenting it out sets the scene to it's default behaviour which is to
automatically expand to encompass any items added to it. The scene size will
be set to the view size when the view is created so you won't see any scroll
bars when the app launches.
Add an item to the scene and then slowly move the item to the left pixel by
pixel until it just barely touches or moves beyond the edge of the view
area. If you do it slowly enough the item disappears. What has happened is
that the scene has been automatically 'grown' to the left and the item has
been moved to the left hand edge of the scene, beyond the current view area.
Use the new scroll bar to look left and you'll find it.
If you move the item more quickly, you won't notice this because the item
blinks for an instant but then reappears where you expect it. The teleport
behaviour only occurs if it is moved very carefully. Moving the item off the
other edges also displays odd behaviour. e.g. slowly moving it off the right
or bottom edges causes it to 'bounce' back a few hundred pixels.
This can be seen more easily by instrumenting the DiagramItem class's
itemChanged method with a print command at line 211 to track the item
co-ordinates as follows:
def itemChange(self, change, value):
if change == QtGui.QGraphicsItem.ItemPositionChange:
for arrow in self.arrows:
You need to rename the app to diagramscene.py so that the console window
displays. You don't need to move the item as carefully, but can see the
anomalous co-ordinates show up in the command window.
It's not clear to me if this is a bug in PyQT, or in the example app, or
more likely I'm just bending the example app in ways it's not designed to be
bent. Any suggestions?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt