PDA

View Full Version : QGraphics view problem



kiranraj
6th March 2007, 10:08
Hi guys ,

I have created an application which contains 100k rectangles and millions of lines.
In both Qt3.3.6( using QCanvas ) and Qt4.2( using QGraphicsScene).

The problem with Qt4.2 is scrolling (with scrollbars) which consumes lot of time.But the same thing
runs smoothly in Qt3.3.6.

Guys, pls let me know the reason for why it takes lot of time .

And is there any property, i need to set in QGraphicsView to improve the same.

Thanks

wysota
6th March 2007, 10:17
Can we see the code of the items? What item classes do you use with QGraphicsView? Did you set their shape() and boundingRect() properly?

kiranraj
6th March 2007, 10:25
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.


QRectF GraphicsLine:: boundingRect () const
{
QPolygon p(4);
//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.

wysota
6th March 2007, 10:38
1.GraphicsLine is derived from QGraphicsItem class and ItemColor (Stores the color of the line)
Why not inherit QGraphicsLineItem.

kiranraj
6th March 2007, 10:49
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

giverson
6th March 2007, 21:28
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...