PDA

View Full Version : QGraphicsView keep shifting origin whenever i add an object in..



chaltier
24th March 2012, 09:59
Need some help here..

Why is it that whenever an object is added to my scene (base on mouse click x-y coordinates), the origin would shift to another part of the view..

Once i drag the item around till the horizontal and verticle scroll bars are enabled..I would then able to add objects in without the view shifting around..

Does anyone know what causes this?

Thanks

wysota
24th March 2012, 12:29
You didn't explicitly set the scene size thus the scene grows as you are adding items to it and since the scene is centered in the view by default, the scene seems to move in the view.

chaltier
24th March 2012, 12:36
Hi thanks for the reply..

If i explicitly set the scene size using setSceneRect, how do i re-enable the dynamically created verticle/horizontal scroll bars when an object go out of view?

thank you..

wysota
24th March 2012, 12:39
If you set the scene size to be larger than the view, scrollbars will be there. You can also zoom in on the scene to make them appear.

chaltier
24th March 2012, 12:43
but i only wan the scroll bars to be there when the scene size gets bigger than the view..

so when the scene is small, no scroll bar, when scene gets big, scroll bars appear..

how do i achieve that?

because right now if i explicitly set the scene size and if i bring a huge image in, a part of it would be cut off (no scroll bar appears for me to navigate the cut-ed part)

thanks again..

wysota
24th March 2012, 12:51
but i only wan the scroll bars to be there when the scene size gets bigger than the view..

so when the scene is small, no scroll bar, when scene gets big, scroll bars appear..

how do i achieve that?
That's what you get by default. I don't see what the problem is then. Maybe it's enough if you change the alignment of the view to be top-left? Then your items won't seem to move however the scene will look strange in the beginning.

chaltier
24th March 2012, 14:03
The default is acting really weird..

after i align the view to left..

the first object, no matter where i place it on the screen, will automatically be placed at the extreme left of the screen..

i wan the view to remain where it is and not move.. T_T

thanks.

wysota
24th March 2012, 14:09
Then set scene boundaries. You can't eat the cake and have the cake. Either the scene adjusts to contents or not, you can't have both at the same time. Since your initial scene has no size, wherever you place the item, the scene will adjust its boundaries to this single item. Since the scene has to be aligned to something your item will be placed to respect that alignment.

Nayrb
12th April 2012, 05:10
Hi guys, I am new to Qt and trying to build a desktop app. I have similar problem here and not sure what I did wrongly. I always have to manually force the scrollbar to come out. I took a video, hope it can better help explain my situation.


http://www.youtube.com/watch?v=qlxsplspsVI&feature=youtu.be

ChrisW67
12th April 2012, 06:24
Video does not work here: "This video is private"

Nayrb
12th April 2012, 19:51
I am so sorry, first time posting on youtube. Can the video be viewed now?

wysota
13th April 2012, 09:25
Set the scene size as I already advised in this thread.

Nayrb
14th April 2012, 12:40
Is there any particular things i should base the scene size on?

wysota
14th April 2012, 13:46
The scene is your world. If you don't know the size of your world, nobody else will either.

Nayrb
9th May 2012, 05:43
I've set the scene size..

now when my scene gets bigger than the view, how do i get the scroll bars to appear?