Difference between QGraphicsView::sceneRect and QGraphicsScene::sceneRect?
-
The documentation is clear that QGraphicsView::sceneRect determines the extent of the scrollable area of the view, and that if this property is not explicitly set on the QGV then it is pulled from QGraphicsScene, and if this is not explicitly set then QGS::sceneRect returns the bounding react of all the items in the scene. The QGV docs are also clear that QGS::sceneRect is used for “item indexing.”
When would You ever want sceneRect on QGV to be different from sceneRect on QGS? That is, why isn’t there just a sceneRect on QGV? The only indication from the docs is that you may want the “item indexing” function on QGS to operate independently of the scrollable area of the QGV, but there is no indication of what “item indexing” is in order to decide which sceneRect property to set.
Cheers,
-Patrick -
@Asperamanca Yes, that is the reason that the QGV sceneRect takes priority. However, I am specifically trying to figure out why there is a sceneRect property on QGS at all.
- You can have a scene without a view (yet). You may want to finish configuring the scene before you attach a view.
- As I wrote, it is relatively easy to get the scene rect from QGraphicsScene from within an item, but if the sceneRect existed only in the view, it would be more complicated, with more checks in the code.
I would argue that most of the time, you attach a single view to the scene, and most of the time where you do attach multiple views, they will be able to share the sceneRect. In that view, overriding the sceneRect in the view is a special case of a special case. Great it is supported, but it should not make everyone's code more complicated.
-
The documentation is clear that QGraphicsView::sceneRect determines the extent of the scrollable area of the view, and that if this property is not explicitly set on the QGV then it is pulled from QGraphicsScene, and if this is not explicitly set then QGS::sceneRect returns the bounding react of all the items in the scene. The QGV docs are also clear that QGS::sceneRect is used for “item indexing.”
When would You ever want sceneRect on QGV to be different from sceneRect on QGS? That is, why isn’t there just a sceneRect on QGV? The only indication from the docs is that you may want the “item indexing” function on QGS to operate independently of the scrollable area of the QGV, but there is no indication of what “item indexing” is in order to decide which sceneRect property to set.
Cheers,
-Patrick@patrickkidd I'm just guessing here, but what if you display a single scene in multiple views, and e.g. want some of the views only to display a part of it? You could then simply restrict the scene rect on that view.
On the other hand, if you want to access the sceneRect from within the scene, life would get a lot more complicated if you had to go via one of potentially multiple views.
-
@patrickkidd I'm just guessing here, but what if you display a single scene in multiple views, and e.g. want some of the views only to display a part of it? You could then simply restrict the scene rect on that view.
On the other hand, if you want to access the sceneRect from within the scene, life would get a lot more complicated if you had to go via one of potentially multiple views.
@Asperamanca Yes, that is the reason that the QGV sceneRect takes priority. However, I am specifically trying to figure out why there is a sceneRect property on QGS at all.
-
@Asperamanca Yes, that is the reason that the QGV sceneRect takes priority. However, I am specifically trying to figure out why there is a sceneRect property on QGS at all.
- You can have a scene without a view (yet). You may want to finish configuring the scene before you attach a view.
- As I wrote, it is relatively easy to get the scene rect from QGraphicsScene from within an item, but if the sceneRect existed only in the view, it would be more complicated, with more checks in the code.
I would argue that most of the time, you attach a single view to the scene, and most of the time where you do attach multiple views, they will be able to share the sceneRect. In that view, overriding the sceneRect in the view is a special case of a special case. Great it is supported, but it should not make everyone's code more complicated.
-
- You can have a scene without a view (yet). You may want to finish configuring the scene before you attach a view.
- As I wrote, it is relatively easy to get the scene rect from QGraphicsScene from within an item, but if the sceneRect existed only in the view, it would be more complicated, with more checks in the code.
I would argue that most of the time, you attach a single view to the scene, and most of the time where you do attach multiple views, they will be able to share the sceneRect. In that view, overriding the sceneRect in the view is a special case of a special case. Great it is supported, but it should not make everyone's code more complicated.
@Asperamanca Ah. now I understand what you wrote in your original reply more clearly. That does make sense, and it looks like the implementation accomplishes that level of flexibility without compromising the most general case.