Results 1 to 4 of 4

Thread: Drawing QGraphicsSvgItem from center

  1. #1
    Join Date
    Mar 2008
    Location
    Norway
    Posts
    7
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Drawing QGraphicsSvgItem from center

    Hi.

    I have an application using QGraphicsView, where I can click in the view to add an SVG item. I want this item to be drawn with the center of the image at the position I click. Right now I get the scene position from the click, and set that as the new items position, but then the item seem to be drawn with this position as its upper left corner...

    Is it something I can do in the SVG file (for example using Inkscape) to let the svg items position be the center of the image, or in the paint method of the item perhaps?

    I guess I could calculate some offset based on the image size and adjust the position based on that, but I hope to avoid that solutions since I would like the item->pos() to represent the actual position.
    Attached Images Attached Images

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

    Default Re: Drawing QGraphicsSvgItem from center

    You can subclass the item and reimplement boundingRect() and paint().

  3. The following user says thank you to wysota for this useful post:

    Mhondoz (14th March 2008)

  4. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing QGraphicsSvgItem from center

    when setting the item position,,, why cant u set it like this..

    say scenePos = mouse position in scene.
    itemPos = scenePos.adjusted(-item.width/2 , -item.height/2);
    u can manipulate the itemposition in this way. seems u are just setting the position of item at scene position of mouse click.
    dont forget to check the boundary lies in scene or not
    Hope it helps

  5. The following user says thank you to aamer4yu for this useful post:

    Mhondoz (14th March 2008)

  6. #4
    Join Date
    Mar 2008
    Location
    Norway
    Posts
    7
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: Drawing QGraphicsSvgItem from center

    @wysota: Yes I know, was just hoping for some easier solution here... Like in Incscape I can set an offset for the graphics so the top left part has negative coordinates and the center of the image is 0,0.

    @aamer4yu: I was trying to avoid to change the position of the item because I may want to use it later on by asking the item for its position (which is lat/lon in a real world map), but I see now that this might not be a problem...

    Anyway, thanks to both of you for the replies.

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.