Issue
I am programming a stacked bar plot in QGraphicsScene
using QGraphicRectItems
. Everything works so far, but it seems as if I change the height of the QGraphicsRectItems
straight after creating it with setRect
, the height is not applied. Strangely, if I rerun the program the height is always changed to the same "random" values.
If I change the height of the QGraphicsRect
s once more, using the same function everything works. Is there anything I need to do after creating a QGraphicsRect
to "register" it or something?
Edit:
The same happens if I change the heights again. I need to do it twice to make the bars adjust their height correctly.
Code:
In my function I change the height of the (stacked) QGraphicsRectItems
with:
accH = 0
for i, h in enumerate(data):
geo = rects[i].rect()
print "before\t\t\t", geo
print "target height\t\t", h
geo.setHeight(h)
geo.setY(accH)
rects[i].setRect(geo)
print "changed geometry\t", geo
print "geometry of updated rect", rects[i].rect()
print "___"
accH += h
print "-----"
rects
is a list of previously created QGraphicsItem
s.
Output of the print statements above with data = [ 98. 263. 6710. 0.]
:
First run:
before PySide.QtCore.QRectF(0.000000, 0.000000, 1.000000, 98.000000)
target height 98.0
changed geometry PySide.QtCore.QRectF(0.000000, 0.000000, 1.000000, 98.000000)
geometry of updated rect PySide.QtCore.QRectF(0.000000, 0.000000, 1.000000, 98.000000)
___
before PySide.QtCore.QRectF(0.000000, 98.000000, 1.000000, 166.000000)
target height 263.0
changed geometry PySide.QtCore.QRectF(0.000000, 98.000000, 1.000000, 263.000000)
geometry of updated rect PySide.QtCore.QRectF(0.000000, 98.000000, 1.000000, 263.000000)
___
before PySide.QtCore.QRectF(0.000000, 361.000000, 1.000000, 6351.000000)
target height 6710.0
changed geometry PySide.QtCore.QRectF(0.000000, 361.000000, 1.000000, 6710.000000)
geometry of updated rect PySide.QtCore.QRectF(0.000000, 361.000000, 1.000000, 6710.000000)
___
before PySide.QtCore.QRectF(0.000000, 7071.000000, 1.000000, -7068.000000)
target height 0.0
changed geometry PySide.QtCore.QRectF(0.000000, 7071.000000, 1.000000, 0.000000)
geometry of updated rect PySide.QtCore.QRectF(0.000000, 7071.000000, 1.000000, 0.000000)
___
Second run:
before PySide.QtCore.QRectF(0.000000, 0.000000, 1.000000, 98.000000)
target height 98.0
changed geometry PySide.QtCore.QRectF(0.000000, 0.000000, 1.000000, 98.000000)
geometry of updated rect PySide.QtCore.QRectF(0.000000, 0.000000, 1.000000, 98.000000)
___
before PySide.QtCore.QRectF(0.000000, 98.000000, 1.000000, 263.000000)
target height 263.0
changed geometry PySide.QtCore.QRectF(0.000000, 98.000000, 1.000000, 263.000000)
geometry of updated rect PySide.QtCore.QRectF(0.000000, 98.000000, 1.000000, 263.000000)
___
before PySide.QtCore.QRectF(0.000000, 361.000000, 1.000000, 6710.000000)
target height 6710.0
changed geometry PySide.QtCore.QRectF(0.000000, 361.000000, 1.000000, 6710.000000)
geometry of updated rect PySide.QtCore.QRectF(0.000000, 361.000000, 1.000000, 6710.000000)
___
before PySide.QtCore.QRectF(0.000000, 7071.000000, 1.000000, 0.000000)
target height 0.0
changed geometry PySide.QtCore.QRectF(0.000000, 7071.000000, 1.000000, 0.000000)
geometry of updated rect PySide.QtCore.QRectF(0.000000, 7071.000000, 1.000000, 0.000000)
___
What I just realized just now while making this output ready for stackoverflow, the problem seems that the height of each QGraphicsRectItem
is the proper height
- its y value
. I tried now to first do setY
and then setHeight
on geo
above. Then the prints suggest that the geometry (rect) of the QGraphicsRects
are correct. But on the QGraphicsView
I do not see any change.
Solution
I found the solution to my problem eventually.
What one has to do is to call setY
before setHeight
on the QRect
defining the geometry of the QGraphicsRect
.
Answered By - P.R.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.