[Qt-interest] QGraphicsItem ignore scene translation/transform?

Samuel Rødal samuel.rodal at nokia.com
Fri Jan 22 13:04:10 CET 2010


ext Thomas Fjellstrom wrote:
> I'm trying to get a few items to completely ignore the scene's current 
> translation and transforms. That is, I'd like the item to stay at a fixed 
> position in the view, regardless of any zooming, or movement in the view 
> itself. And do that without it looking like I'm manually moving the item 
> with the view (ie: it lagging slightly behind the scrolling).
> 
> I've played with the QGraphicsItem::ItemIgnoresTransformations flag, it 
> definitely doesn't ignore translations in the scene at all, and it seems to 
> mess up the "y rotate" animation I added to a couple items. It looks like 
> its shifting the item's coordinates around a little. I use: 
> setTransformOriginPoint(size().width()/2, size().height()/2); to set the 
> transform point to the centre of the item, so my item (without the ignore 
> flag) flips around the y axis (centre of the item) nicely. With the ignore 
> flag, it flips around the right hand edge of the item, and seems to shift 
> its x position as it flips.
> 
> I'm using Qt 4.6.0 (from qt.nokia.com, not a distro package), on linux 
> 2.6.32 + KDE 4.3.4.
> 
> Is there any way to get the behaviour I'm looking for? Thank you.

Have you considered not transforming the view, and instead making all 
the transformable item children of a top-level invisible graphics item? 
Then you could transform all the child items by transforming the 
top-level, leaving the non-transformable items as they were.

Regarding ItemIgnoresTransformations, the docs say "The item ignores 
inherited transformations (i.e., its position is still anchored to its 
parent, but the parent or view rotation, zoom or shear transformations 
are ignored)."

So yes, translation will not be ignored.

--
Samuel




More information about the Qt-interest-old mailing list