PDA

View Full Version : Setting focus on Canvas



Kapil
9th May 2006, 10:16
Hi..

I have created a canvas and have created lot many items on it...
Now when i call the zoom functions which sets the scale to double, the point i was on is lost.
i am not able to keep the focus as the same on the canvas item which was there before the zoom event calls..
For eg if my 10 item is on display on the canvas, after zoom i should have the same region as display but what happens is that the region gets changed and my 5th item comes into display...
how do i extract the coordinate set of the canvas into display..

Thanks,
Kapil

wysota
9th May 2006, 11:49
QCanvasView inherits QScrollView, you can check the value of its scrollbars to have the left upper corner of the display. Then, after zooming, scale those values and use setContentPos() to move the contents to desired coordinates.

Kapil
9th May 2006, 11:55
QCanvasView inherits QScrollView, you can check the value of its scrollbars to have the left upper corner of the display. Then, after zooming, scale those values and use setContentPos() to move the contents to desired coordinates.


Hi..

Thanks a lot for the reply...

Ok...Now i understood the procedure...
Scaling to the value means that i would have to write my own calculating function which would tell me the precentage move of the point after zooming value (scale value) and then i would have to set that point on the ScrollView..

with regards,
Kapil

Kapil
10th May 2006, 07:58
Hi..

i looked over all the functions of the QScrollView but then none of them is giving me the exact vale of the top left most corner...
The function leftMargin() always returns me 0 no matter what my viewport is...
The function contentsX() returns me a value different from that of the top left most corner pixel value which i find out by clicking on the point...
i dont know which function of all would give me the value..

Also is there any function which can give me the centre point of the visible canvas area...

Thanking you..

with regards,
Kapil

wysota
10th May 2006, 09:05
Access the scrollbars and get their values.

Kapil
12th May 2006, 11:07
Access the scrollbars and get their values.

Hi...

i dont know which ways to access it .. i could not find the function in the Q3ScrollView class.. i just tried all the functions in it but none was able to give me the soln..

Plz help me out with the function name which would do so.. I am sorry for asking a direct solution but i have tried on it for few days and then i have come to it.. i have checked thru all the relevant classes and their function but to no help..
i would be really thankful if u could help me out with it..

Thanking you a lot..

with regards,
Kapil

wysota
12th May 2006, 11:18
Don't tell me you didn't find Q3ScrollView::horizontalScrollBar() and Q3ScrollView::verticalScrollBar()...

Kapil
17th May 2006, 06:05
Hi..


i tried doing this way..
I am returned some point but they do not match with any of the corners or center on the canvas.. sometimes the point does not even lie on the canvas..

The function which i used for wach horizontal and vertical scrollbar was value()
Also i tried using the pos function but it returned me 0 always and also the x() and y() functions..

how do i get the values of the scrollbar on the canvas...

Plz suggest me something...

Thanking you,

with regards,
Kapil

munna
17th May 2006, 06:11
how about viewportToContents() ?

Kapil
17th May 2006, 08:11
how about viewportToContents() ?

viewportToContent: "Translates a point (vx, vy) on the viewport() widget to a point (x, y) in the contents."

How does it help me... I don't know the point on the canvas to set focus to...
Its this way that i am shown a part of the canvas.. now when i zoom the canvas, the part of the canvas which i was viewing before should be the one which i am viewing just that it is zoomed....
i should be nearby the same coordinate set where i was earlier...
but right now it just gets lost...

thank you,

with regards,
Kapil

Kapil
17th May 2006, 13:55
Thanks a lot all..

i was able to do it... basically i had to apply some mathematics in coming to the required value and location.. now its working pretty fine..

with regards,
Kapil