Batu olm bi gavra hele ya felaket sıkıldım. batu olmazsa seyhun o da olmazsa bu işin ordinasyüsü levent.
Batu olm bi gavra hele ya felaket sıkıldım. batu olmazsa seyhun o da olmazsa bu işin ordinasyüsü levent.
The problem here is basicly because of item's removal from the scene bounding rect. So how can I put the item back into the scene rectangle when it's gone out of it by zooming in action , if I zoom out in the scene again?
Why are you managing yourself the items viewed in your scene?
Since Qt do the job for you and compute the visible items based on QGraphicsItem::boundingRect, you will get in QGraphicsView::drawItems the list of visible items.
So no need to remove or add items.
Are you computing the zoom yourself in the scene, in your custom items or elsewhere?
I guess you misunderstood me. I didn't remove or add items when I zoom in or zoom out. This is what I think as a possible reason that the items are no longer visible once they are off the scene's bounding rectangle. It is also strange that the program still enters item's paint method although it's not drawn.
I deal zooming stuff in the view by the way.
So that means that the item are seen by Qt, according to its bounding rect.
Can you post a simplified version of your zoom function?
There is probably a coordinates conversion error of your items position, so they are drawn out of the viewed rect.
Another questions :
* Why not using Qt built-in QGraphicsView::scale?
* Do you manage derived QGraphicsItem with overloaded paint?
Hi,
sorry but I can't because I'm using different library for such operations(zooming, rotating etc.) and the functions are hidden which means not available. I just called setRange(+/- rangeAmount) and it does. Sorry fot that.
By the way, don't you think that items would have drawn wrongly at the begining or at the situations in which the items are in still scene's rectangle if there is a coordinate error?
Anyway regarding your last questions,
I didn't prefer to use it because I deal with geographic coordinates( latitudes and longitudes) so that's why we use different library as I mentioned.
And I don't think my paint functions are overloaded. They're just dealing with paint issues.
That why we can help you if you provided some code. Maybe in your loop there is something obvious you don't see now. Maybe your are cumulating zoom scale factor instead of applying it globally, maybe it is the result of integer division...
Can't you even sum up the data life cycle : creation and adding to the scene, setting position and geometry? It is hard to help you without knonwing what your are doing.
If you never scale the view by native Qt method scale, I guess you are overloading the paint method of the view and compute yourself relative position of items and their size in pixel coordinates. But then it is only painting, isn't it?
In that conditions what is the difference with drawing in a QWidget?
It is only a matter of coordinate system reference. You only need to choose one for you scene, and convert item coordinates when adding.
Since 1 unit is 1 pixel at scale 1, you can fix your system projection and unit, then position your items and set their size. Then let Qt do the rendering of visible item for you.
All you have to do it convert your data when creating items and painting them, according to the projection you are using for your scene : plane projection for latitude/longitude in degrees or seconds, or UTM or another metric projection
An easy way to use QGraphicsView is to choose a projection system for your scene, geographic or metric.
So you can derived QGraphicsItem :
* when you add it on the scene, just set a member data to your item (passing in constructor for instance)
* set its position in scene coordinate (using your conversion libraries),
* implement the QGraphicsItem::boundingRect, that return the rect in scene coordinate (you can use your libraries to compute it and even optimize in your object the way to do it only once,
* overload QGraphicsItem::paint. The paint method gets in its arguments the rect of visible portion of your data ( in scene coordiante so in the projection you have chosen) and the level of detail (the scale factor) set by the QGraphicsView::scale. You can then use in paint event the library you want you draw in the painter, in relative pixel coordinate of the item. If any part of the rect is visible in the scene, a paint is triggered.
Therefore, picking and moving items, zooming and navigating through the view is managed by Qt and call paint for item that need to be displayed.
Instead of concentrate on the view, can't you focus on items?
This may save you a lot of work, don't you think?
Bookmarks