Results 1 to 11 of 11

Thread: Setting focus on Canvas

  1. #1
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Setting focus on Canvas

    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
    All you have to decide is what to do with the time that is given to you

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting focus on Canvas

    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.

  3. #3
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting focus on Canvas

    Quote Originally Posted by wysota
    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
    All you have to decide is what to do with the time that is given to you

  4. #4
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting focus on Canvas

    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
    All you have to decide is what to do with the time that is given to you

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting focus on Canvas

    Access the scrollbars and get their values.

  6. #6
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting focus on Canvas

    Quote Originally Posted by wysota
    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
    All you have to decide is what to do with the time that is given to you

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting focus on Canvas


  8. #8
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting focus on Canvas

    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
    All you have to decide is what to do with the time that is given to you

  9. #9
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting focus on Canvas

    how about viewportToContents() ?

  10. #10
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting focus on Canvas

    Quote Originally Posted by munna
    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
    All you have to decide is what to do with the time that is given to you

  11. #11
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting focus on Canvas

    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
    All you have to decide is what to do with the time that is given to you

Similar Threads

  1. Replies: 2
    Last Post: 5th March 2009, 10:34
  2. Replies: 0
    Last Post: 25th February 2009, 07:15
  3. Force focus to a QTabWidget page's widget
    By thomaspu in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2008, 06:54
  4. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 06:09
  5. Tab/Enter focus problem
    By b1 in forum Qt Programming
    Replies: 4
    Last Post: 23rd October 2006, 23:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.