Hello,
I am creating a QGraphicsScene containing only 1416 rects with the following code (see next thread).
As you can see in traces, I have very bad performances:
## >SKGTableWithGraph::redrawGraph
## >SKGTableWithGraph::redrawGraph-remove scene
## <SKGTableWithGraph::redrawGraph-remove scene TIME=0.287117 ms
## >SKGTableWithGraph::redrawGraph-create scene
## Scene rect:-10,-354833,394415,394435
## Items:24x59=1416
## <SKGTableWithGraph::redrawGraph-create scene TIME=57306.6 ms
## >SKGTableWithGraph::redrawGraph-add scene to view
## <SKGTableWithGraph::redrawGraph-add scene to view TIME=1.1489 ms
## <SKGTableWithGraph::redrawGraph TIME=57312.6 ms
## >SKGTableWithGraph::redrawGraph
## >SKGTableWithGraph::redrawGraph-remove scene
## <SKGTableWithGraph::redrawGraph-remove scene TIME=0.287117 ms
## >SKGTableWithGraph::redrawGraph-create scene
## Scene rect:-10,-354833,394415,394435
## Items:24x59=1416
## <SKGTableWithGraph::redrawGraph-create scene TIME=57306.6 ms
## >SKGTableWithGraph::redrawGraph-add scene to view
## <SKGTableWithGraph::redrawGraph-add scene to view TIME=1.1489 ms
## <SKGTableWithGraph::redrawGraph TIME=57312.6 ms
To copy to clipboard, switch view to plain text mode
57s are needed just to build the scene 
In my code, if I comment the addRect methods like this:
if (mode==0) {
//STACK
if (val>0) {
//graphItem=scene->addRect(width*x, -yPlus, width, -val, QPen(), QBrush(color));
yPlus+=val;
if (yPlus>ymax) ymax=yPlus;
} else if (val<0) {
//graphItem=scene->addRect(width*x, -yMoins, width, -val, QPen(), QBrush(color));
yMoins+=val;
if (yMoins<ymin) ymin=yMoins;
}
} else if (mode==1) {
if (mode==0) {
//STACK
if (val>0) {
//graphItem=scene->addRect(width*x, -yPlus, width, -val, QPen(), QBrush(color));
yPlus+=val;
if (yPlus>ymax) ymax=yPlus;
} else if (val<0) {
//graphItem=scene->addRect(width*x, -yMoins, width, -val, QPen(), QBrush(color));
yMoins+=val;
if (yMoins<ymin) ymin=yMoins;
}
} else if (mode==1) {
To copy to clipboard, switch view to plain text mode
then I have very good performances
but my scene is empty (of course).
## >SKGTableWithGraph::redrawGraph
## >SKGTableWithGraph::redrawGraph-remove scene
## <SKGTableWithGraph::redrawGraph-remove scene TIME=0.179953 ms
## >SKGTableWithGraph::redrawGraph-create scene
## Scene rect:-10,-354833,394415,394435
## Items:24x59=1416
## <SKGTableWithGraph::redrawGraph-create scene TIME=9.6991 ms
## >SKGTableWithGraph::redrawGraph-add scene to view
## <SKGTableWithGraph::redrawGraph-add scene to view TIME=0.407059 ms
## <SKGTableWithGraph::redrawGraph TIME=13.9419 ms
## >SKGTableWithGraph::redrawGraph
## >SKGTableWithGraph::redrawGraph-remove scene
## <SKGTableWithGraph::redrawGraph-remove scene TIME=0.179953 ms
## >SKGTableWithGraph::redrawGraph-create scene
## Scene rect:-10,-354833,394415,394435
## Items:24x59=1416
## <SKGTableWithGraph::redrawGraph-create scene TIME=9.6991 ms
## >SKGTableWithGraph::redrawGraph-add scene to view
## <SKGTableWithGraph::redrawGraph-add scene to view TIME=0.407059 ms
## <SKGTableWithGraph::redrawGraph TIME=13.9419 ms
To copy to clipboard, switch view to plain text mode
Conclusion: Bad performances are due to addRect method.
Question: What is the solution to improve performances ?
I don't understand why "40000 Chips" example is very fast and not my "1416 rects" example !
Bookmarks