PDA

View Full Version : How to draw QCanvasPolygonItem that doesn't change size on zoom? (QT3)



windflower
26th March 2007, 00:42
QT3
I have a pixmap background in a QCanvas which the user can zoom in to find details in then click on the details to mark them. I draw a QCanvasPolygonItem subclass to mark the spot. I would like the marker to appear the same size as the user zooms in an out.

Zooming is done in the conventional manner through the QCanvasView using the QWMatrix to zoom (and pan). The normal behavior is for the marker to appear larger when the user zooms in.

I draw the marker in the drawShape methd of my subclass. How can I work with the world matrix to maintain the same position on the canvas relative to the background but not change size when zooming?

-- Windflower

luffy27
15th May 2007, 17:48
I have the same problem.
Is there any possible solution to deal with the problem.
Thanks a lot.

Bitto
21st May 2007, 22:12
Getting QCanvasItems to work this way is hard; QCanvas indexes items based on their geometry relative to the canvas, and it assumes that items stay the same size regardless of QCanvasView's transformation. Whereas if the item should stay the same size regardless of the transformation, that means the view owns the item's geometry, not the canvas. So QCanvas would claim that items were at one spot, whereas the view would actually render them somewhere else.

You _can_ make this work, but you need to hijack QCanvasView::paintEvent() and do _all_ the rendering yourself. If you want to interact with the items, you also need to write subtle code in QCanvasView::mouse*Event() handlers. It's very hard to get right, unfortunately. But possible. An easier approach might be to just reimplement QCanvasView::paintEvent() and draw your untransformed shapes directly after calling QCanvasView's base paintEvent implementation.

Unfortunately, QCanvas doesn't help you a lot in this sense; it simply wasn't designed to support such items.

[Fyi: In Qt 4, all this trouble is hidden behind a simple flag: QGraphicsItem::ItemIgnoresTransformations (http://doc.trolltech.com/4.3/qgraphicsitem.html#GraphicsItemFlag-enum). If you set it on an item, the item will remain the same size (w/transformations) regardless of the view. And interaction works like normal.]