Albert Astals Cid wrote:
>> Hi, Albert. Can you please show the code that worked before and not now?
> I attach both the code that works with 4.4.RC1 and the one that worked on
> 4.3
> ToDraw inherits QGraphicsSvgItem
> Basically the code "cuts" the SVG when it's outside some area.
> I know it's a probably subobtimal way of doing it but it works well enough
> for my use case.
> As you see the only difference is the pos() call

Hi, Albert. You can't use pos() to draw inside paint(); the paint() function
renders in local coordinates. If you render using pos(), you'll always
shift the rendering twice relative to the position of the item (but the
painter is always translated with the item's position).

Are you able to isolate this problem with simpler code? The implementation
of paint() seems to be wrong. It looks like you're trying to implement your
own "pixmap caching", such as QGraphicsSvgItem::setCachingEnabled in Qt 4.3
or QGraphicsItem::setCacheMode in Qt 4.4. Could this be correct?

        const QRectF &bounds = transform().mapRect(boundingRect());

This maps your item's bounding rect using your item's transform. However,
this transform does not compensate for the item's position. So depending on
your item's position, bounds will be shifted.

        const QRectF &backgroundBounds =
m_background->transform().mapRect(renderer()->boundsOnElement("background"));

I assume m_background is the parent item. This code maps the local SVG's
background element bounding rect to the m_background's parent, again not
adjusting for m_background's position. Note that the parent's transform and
your item's local transform and both items' positions must be multiplied
for this transformation to work.

        double xMaxEdge = pos().x() - backgroundBounds.x() + bounds.width();
        double yMaxEdge = pos().y() - backgroundBounds.y() +
bounds.height();

These variables seem to add the local position of the item to
backgroundBounds top-left corner, I don't understand this code...

If you look at mapToItem() or mapToScene(), these functions help you map
coordinates correctly. Inside the source code of QGraphicsScene
(qgraphicsscene.cpp), you'll see in the drawItemHelper function how we
implement caching so that it works for all kinds of transforms.

I don't know why your code has regressed in Qt 4.4, it's hard to say.

-- 
Andreas Aardal Hanssen
Senior Software Engineer, Team Lead / Widgets
Trolltech ASA - Sandakerveien 116, NO-0484 Oslo, Norway

To unsubscribe - send "unsubscribe" in the subject to [EMAIL PROTECTED]

Reply via email to