PDA

View Full Version : QGraphicsScene & QGraphicsView help please



munna
22nd May 2009, 11:53
Hi!

I have an application where the user can draw any diagram. The diagram area is resizeable. For this I am reimplemented QGraphicsScene and QGraphicsView classes.

1. sceneRect is initially lets sat set to (0, 0, 100, 100) which is smaller than the viewport of QGraphicsView.
2. I draw a resize handler in the function drawForeground in the sceneRect. It appears fine at the right and the bottom edges of the scene in the viewport.
3. I have reimplemented the mouseMoveEvent, mousePressEvent and mouseReleaseEvent of QGraphicsScene such that when the mouse is pressed on the resize handler and dragged the scene is resized by calling setSceneRect.

Now, when the size of the sceneRect becomes more than viewport scrollbar appears but they do not drag along and therefore the size cannot be resized smoothly.

Also, when the scroll bars appear and if we try to reduce the size of the sceneRect using the handlers at the edges, the scrollbars disappear immediately.

Can you someone please help me impelement this the right way?

Thanks,

alisami
22nd May 2009, 12:24
you can set the size of the scene rectangle to the QGraphicsView's maximum viewport size.

in your QGraphicsView's resizeEvent, you can set the sceneRect to the maximum viewport size of the QGraphicsView by using QAbstractScrollArea::maximumViewportSize.

this way you will have the same sized scene and view and no scrollbar will be seen.

I hope this was what you need..

munna
22nd May 2009, 12:53
this way you will have the same sized scene and view and no scrollbar will be seen.

I hope this was what you need..


I think you misunderstood my question. Its not that I don't want scrollbars to appear. Infact, I do want scrollbars to appears. The problem is that they are not behaving correctly.

When I resize sceneRect dynamically using the resize handler everything is fine till the the size of the sceneRect is smaller than the viewable area of the graphics view. Once is grows bigger than that, the scroll bars appear but then they do not scroll along and hence the size cannot be increased further using the resize handler.

Also, when the sceneRect size is greater than the viewable area and if we try to reduce the size, then the scrollbars disappear immediately.

I hope its clearer this time.

Thanks,

wagmare
22nd May 2009, 13:16
i am not sure but ..


fitInView(scene->sceneRect(), Qt::KeepAspectRatio);


which aspect ratio u are using ...? may be this one creates problem ...

alisami
25th May 2009, 11:51
munna, can you provide an example code which generates the error?

munna
25th May 2009, 12:08
Never mind, I fixed this problem.

high_flyer
13th February 2017, 12:30
@munna would be nice if you post the solutions for the benefit of other users that face a similar problem in the future.