Hi,
Im still doing my Polygon Path and I came across a following problem,
I'm guessing this could be a bug. Inside of MyGraphicsView class i
create a MyPolygon instance. MyPolygon class has an inner class
definition of MyGraphicsEllipseItem which I use to visualize control
points (vertices of the polygon). Now, when I press a mouse button over
such ellipse the mousePressEvent is called and in this method I want to
retrieve this ellipse item's position and print it in the console
->System.out.println("X "+this.scenePos().x()+" Y
"+this.scenePos().y());. Unfortunately i allways get X 0 Y 0 although
ellipses are placed in different positions then (0,0) in the scene. I
think I tryed everything by now. I can easily overcome this problem by
adding the position variable to the MyGraphicsEllipseItem where I keep
the postion but I don't like to waste resources so if You could please
explain why this doesn't work, I would be thankfull.
Here a cropped version of MyPolygon :
public class MyPolygon {
private QGraphicsScene scene;
QGraphicsItemInterface parent;
MyPolygon(QGraphicsItemInterface parent, QGraphicsScene scene,
QPointF mousePos){
this.scene = scene;
this.parent = parent;
}
protected void addVertex(QPointF pos){
MyGraphicsEllipseItem Vertex = new
MyGraphicsEllipseItem(pos.x()-8, pos.y()-8, 15, 15, this.parent,
this.scene);
Vertex.setPen(new QPen(new QColor(50, 100, 120, 200)));
Vertex.setBrush(new QBrush(new QColor(200, 200, 210, 120)));
Vertex.setAcceptsHoverEvents(true);
Vertex.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable,
true);
Vertex.setZValue(1);
}
private class MyGraphicsEllipseItem extends QGraphicsEllipseItem{
//QPointF position;
MyGraphicsEllipseItem(double x, double y, double w, double h,
QGraphicsItemInterface parentItem, QGraphicsScene scene){
super(x,y,w,h, parentItem, scene);
//position = new QPointF(x,y);
}
@Override
public void mousePressEvent(QGraphicsSceneMouseEvent event){
System.out.println("X "+this.scenePos().x()+" Y
"+this.scenePos().y());
// System.out.println("some X "+position.x()+" Y "+position.y());
super.mousePressEvent(event);
}
}
}
Dawid
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest