PDA

View Full Version : QGraphicsPathItem



tonio
25th June 2009, 08:48
Hello,

I'm using a path item to draw a line that connects 2 other items.
I have a strange selection problem. When I click not far away from the path item, my program says that the item is selected. So I looked around in the net and I found this post:

http://labs.trolltech.com/blogs/2008/01/08/accurate-update-regions-for-thin-qgraphicsitems/

So I tried to define a new bounding region granularity but every this when the granularity is different from 0, my program crashes.
Here is what my GDB says:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb6e9e6c0 (LWP 10224)]
0xb7de7985 in QGraphicsItem::boundingRegionGranularity () from /usr/lib/libQtGui.so.4

And I don't have an idea why ...
Do you have any ideas and an example for how to use this setBoundingRegionGranularity().
In my program I'm using this method in the constructor of the class that is representing the path item (the class is a subclass of the QGraphicsPathItem).

Thank you in advance.

Best regards,

Anton

zgulser
25th June 2009, 10:32
Hi Anton,

I don't know the boundingRegion(..) function, but shape() could be the alternative way for what you trying to achieve by using boundingRegion(..).

Zeck

tonio
25th June 2009, 11:21
Hi Anton,

I don't know the boundingRegion(..) function, but shape() could be the alternative way for what you trying to achieve by using boundingRegion(..).

Zeck

Yes, I've already tried to implement the shape() method:




QPainterPath Wire::shape() const{

return path(); //Wire is a sublcass of QGraphicsPathItem
}


but this gives me the same result.
I found an example that has a similar visual result of what I would like to make, but there they use only a QPainterPath and not an Item. And in my program I have to use items..
Here is the example:

http://doc.trolltech.com/4.4/demos-pathstroke.html

Anton

tonio
25th June 2009, 11:28
In fact I'm trying to make lines that are connecting my other items, something like in Visual Studio or similar softs. There the user can drag the lines and adjust them in a way to obtain a more clear scheme ...

Anton

tonio
25th June 2009, 15:35
I found the solution in some old post.
For QGraphicsPathItem we should redefine the shape() method using the QPainterPathStroker class and especially the createStroke() method.

Anton