Results 1 to 3 of 3

Thread: How do I change QGraphicsSvgItem bounding rectangle to be negative

  1. #1
    Join Date
    Mar 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How do I change QGraphicsSvgItem bounding rectangle to be negative

    Hi Guys

    First post here.

    I'm developing a Qt version of the Cairo Clock for the Nokia N900, and I have a rendering problem with certain SVG Files inside a QGraphicsview.

    Many of the SVG Themefiles have some part of the clock hands set outside of the document as the center of the hand is set to (0,0) in the document.

    here is a picture of the file



    When I get the bounding rectangle for the item, it gives me the size of the document from (0,0) with a width and height of the document, in this case its 100x100.
    I assume that that Qt does not know that the back end and top half of the clockhand is there, and I get clipping of the hand when it is rendered. If I zoom right in the whole of the clock hand is rendered, but zoom out it looses the back end of the clock hand.

    Here is a picture of the problem



    Here is a picture of it zoomed in



    So I assume it has read the whole of the file in, but I just need to tell Qt that the bounding box is a little larger to the negative, ie a negative start point, but I cant for the life of me change it.

    I am using python and PyQt like this, but it does not change it.

    Qt Code:
    1. self.svgSecond=QGraphicsSvgItem(self.themeDir+"clock-second-hand.svg",)
    2. self.svgSecond.boundingRect().setX(-10)
    To copy to clipboard, switch view to plain text mode 

    The problem is on both my N900 and my Linux OpenSuse dev machine.
    Any clues of where to go from here much appreciated.
    Last edited by mikec; 29th March 2010 at 10:46.

  2. #2
    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: How do I change QGraphicsSvgItem bounding rectangle to be negative

    I dont know about python,,, but you can look for these points in you code -
    - Are Z values set properly ?

    Also you cannot set bounding rect as self.svgSecond.boundingRect().setX(-10). This will only set x for the temporary rect returned by bounding rect.
    The values of bounding rect is returned from boundingRect() function. You will need to override that function by subclassing the item.

    But still, seems you are missing something with the positions of items... walk through your code again

  3. #3
    Join Date
    Mar 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How do I change QGraphicsSvgItem bounding rectangle to be negative

    Many Thanks

    I think I have solved it by setting the viewbox for the SVG negative, and then using a transform rotate instead of rotate like this.

    To Rotate 90 degrees
    Qt Code:
    1. self.svgSecond=QGraphicsSvgItem(self.themeDir+"clock-second-hand.svg",)
    2. self.srenderer=self.svgSecond.renderer()
    3. svgRect=QtCore.QRect()
    4. svgRect.setX(-10)
    5. svgRect.setY(-1)
    6. svgRect.setWidth(100)
    7. svgRect.setHeight(100)
    8. self.srenderer.setViewBox(svgRect)
    9. self.svgSecond.setPos(self.centerx-10, self.centery-1)
    10. self.scene.addItem(self.svgSecond)
    11. self.svgSecond.setTransform(QtGui.QTransform().translate(10, 1).rotate(90).translate(-10, -1))
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QGraphicsSvgItem, problem with scaling (invalid bounding rect)
    By Józef Paczenko in forum Qt Programming
    Replies: 3
    Last Post: 8th June 2010, 08:58
  2. Replies: 3
    Last Post: 30th March 2010, 15:04
  3. Getting the bounding rectangle
    By ioannis in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2009, 00:41
  4. QGraphicsView : change selected rectangle style
    By kghose in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2008, 18:12
  5. Html text bounding rectangle
    By bunjee in forum Qt Programming
    Replies: 8
    Last Post: 15th May 2008, 11:25

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.