PDA

View Full Version : How do I change QGraphicsSvgItem bounding rectangle to be negative



mikec
29th March 2010, 10:32
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

http://farm3.static.flickr.com/2736/4472966686_8964649864_o.png

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

http://farm5.static.flickr.com/4004/4472980886_42f9880b22_o.png

Here is a picture of it zoomed in

http://farm5.static.flickr.com/4027/4472981486_2d99c317ab_o.png

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.



self.svgSecond=QGraphicsSvgItem(self.themeDir+"clock-second-hand.svg",)
self.svgSecond.boundingRect().setX(-10)

The problem is on both my N900 and my Linux OpenSuse dev machine.
Any clues of where to go from here much appreciated.

aamer4yu
29th March 2010, 12:21
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

mikec
29th March 2010, 12:34
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


self.svgSecond=QGraphicsSvgItem(self.themeDir+"clock-second-hand.svg",)
self.srenderer=self.svgSecond.renderer()
svgRect=QtCore.QRect()
svgRect.setX(-10)
svgRect.setY(-1)
svgRect.setWidth(100)
svgRect.setHeight(100)
self.srenderer.setViewBox(svgRect)
self.svgSecond.setPos(self.centerx-10, self.centery-1)
self.scene.addItem(self.svgSecond)
self.svgSecond.setTransform(QtGui.QTransform().tra nslate(10, 1).rotate(90).translate(-10, -1))