Re: QGraphics view problem
Can we see the code of the items? What item classes do you use with QGraphicsView? Did you set their shape() and boundingRect() properly?
Re: QGraphics view problem
1.GraphicsLine is derived from QGraphicsItem class and ItemColor (Stores the color of the line)
2. GraphicsRect is derived from QGraphicsRectItem.
Bounding rectangle of GraphicsLine is shown below.
Code:
QRectF GraphicsLine
:: boundingRect () const {
//Q3PointArray p(poly);
int xi = int(x());
int yi = int(y());
int pw = 1;//pen().width();
int dx = (x1-x2);
if( dx<0)
dx= -dx;
\\ int dy = y1-y2;
if(dy<0)
dy=-dy;
pw = pw*4/3+2; // approx pw*sqrt(2)
int px = x1<x2 ? -pw : pw ;
int py = y1<y2 ? -pw : pw ;
if ( dx && dy && (dx > dy ? (dx*2/dy <= 2) : (dy*2/dx <= 2)) ) {
// steep
if ( px == py ) {
p
[0] = QPoint(x1
+xi ,y1
+yi
+py
);
p
[1] = QPoint(x2
+xi
-px,y2
+yi
);
p
[2] = QPoint(x2
+xi ,y2
+yi
-py
);
p
[3] = QPoint(x1
+xi
+px,y1
+yi
);
} else {
p
[0] = QPoint(x1
+xi
+px,y1
+yi
);
p
[1] = QPoint(x2
+xi ,y2
+yi
-py
);
p
[2] = QPoint(x2
+xi
-px,y2
+yi
);
p
[3] = QPoint(x1
+xi ,y1
+yi
+py
);
}
} else if ( dx > dy ) {
// horizontal
p
[0] = QPoint(x1
+xi
+px,y1
+yi
+py
);
p
[1] = QPoint(x2
+xi
-px,y2
+yi
+py
);
p
[2] = QPoint(x2
+xi
-px,y2
+yi
-py
);
p
[3] = QPoint(x1
+xi
+px,y1
+yi
-py
);
} else {
// vertical
p
[0] = QPoint(x1
+xi
+px,y1
+yi
+py
);
p
[1] = QPoint(x2
+xi
+px,y2
+yi
-py
);
p
[2] = QPoint(x2
+xi
-px,y2
+yi
-py
);
p
[3] = QPoint(x1
+xi
-px,y1
+yi
+py
);
}
return p.boundingRect();
Thanks.
Re: QGraphics view problem
Quote:
Originally Posted by
kiranraj
1.GraphicsLine is derived from QGraphicsItem class and ItemColor (Stores the color of the line)
Why not inherit QGraphicsLineItem.
Re: QGraphics view problem
Why not inherit QGraphicsLineItem.
I created the application to compare the performance ( memory usage and speed)
b/w QCanvas and QGraphicsView.
Initially i used QGraphicsLineItem, Since it uses double( Wider than int )to store the co-ordinates
I didn't prefer it. So i created GraphicsLine, which stores co-ordinates in ints.
Thanks
Re: QGraphics view problem
It's probably in double format because that's the format all the calculations should need to be done in. It's possible it has to recast everything on the fly but I'm not sure on that.
I can't think of any reason they wouldn't give us an overloaded int function, otherwise, since all scene coordinates are effectively integers, anyway.
I guess it's a precision over memory usage balance since they don't figure anyone will actually put 100's of thousands of polygons in a scene.
I only put about 9000 in my largest one...