PDA

View Full Version : again QGraphicsView + steady(unmoved) Item



medved6
5th September 2010, 04:07
Hello Everybody

I have a scene with several items on it. I applay transformations on the scene ( move, zoomin=scale, rotation and so on ).

But I want to have some item( some cotroll like button or may be logo ) alway be at the top-right corner of the scene and has the same size and ignores any transformations.



theItem.setFlag(QGraphicsItem::ItemIgnoresTransfor mations, true);

works good except the case: if I scale or move the scene, theItem moves as well ( make sence, it keeps it's position on the scne ).

So how can I make Item unmovable in viewport() coordinate system?

Generel task is to create some controll( like button ) and put it on top of the scene. May be to use item is not very efficient here?

Thank you!

tbscope
5th September 2010, 08:10
I guess you should put that item (and its size) relative to the view instead of absolute in the scene.

http://doc.qt.nokia.com/4.6/graphicsview.html#the-graphics-view-coordinate-system

medved6
5th September 2010, 09:07
Yes. I understand that.
But how exactly should I do it? The only way I see so far is to do it manually every time I apllay scale to the scene.
Any other ways?

wysota
5th September 2010, 09:16
So how can I make Item unmovable in viewport() coordinate system?
You can make it a widget and place it inside the view (but not the scene). Then it will be immune to all view transformations (you're transforming the view, not the scene).

medved6
5th September 2010, 19:49
But is there any way to solve my issue with Item(not with wiget) ?
The reason I'm asking: I have some advanced Item and I want to make it steady.

ecanela
5th September 2010, 20:14
you can draw directly in the view, using the function QGraphicsView::drawForeground()

please check the post:
http://www.qtcentre.org/threads/27455-QGraphicsItem-subclass-access-to-QGraphicsView-size?p=130114&highlight=#post130114

to draw a item directly in the view, use the paint() funtion from the Items. using the painter provided for the QGraphicsView subclass.

wysota
5th September 2010, 20:28
But is there any way to solve my issue with Item(not with wiget) ?
The reason I'm asking: I have some advanced Item and I want to make it steady.

Yes, you have to move the item on the scene every time you transform the view.


you can draw directly in the view, using the function QGraphicsView::drawForeground()
This draws in scene coordinates so it's practically useless here especially if one needs to handle some input events with the item.

medved6
5th September 2010, 23:01
Thank you!
It seems like I'm going to implement my view in the way that it will take care about all steady Items manually.