[PyQt] Problem with colored rectangles

David Boddie david at boddie.org.uk
Sun Feb 20 00:15:47 GMT 2011


On Sat Feb 19 22:22:10 GMT 2011, shi dingan wrote:

> I have a problem with my code when I try to draw two rectangles with
> overlap.
> I draw a red one, then a green with a small part of it overlapping the red
> rectangle.
> But when I refresh the scene, I have a random behavior, that is, sometimes
> only the red rectangle appears and sometimes both rectangle appear.
> Is it a normal behavior?

Really, both should appear. I think the confusion arises because the green
one lies within the space occupied by the red one.

> I was expecting to see always both rectangle since the
> red one is always the first one added to the scene...

Sometimes the red one appears on top of the green one. Because it covers
the same area as the green rectangle, it looks like only the red rectangle
is added to the scene. To make the green rectangle appear on top, set a
Z value for each of them, but make sure the green rectangle has a higher
value than the red, like this:

  zone1.setZValue(0)
  zone2.setZValue(1)

David


More information about the PyQt mailing list