lni
1st July 2011, 08:35
Hi,
I need to draw 12,000 arrows pointing to different directions depending on data. It take very long time (about 1.5 seconds) to finish.
Following is the codes. If I comment out painter->drawPolyon(...), it only takes 0.037 seconds. Is there a way to speed it up? Thanks!
QRectF Rect( QPointF( 0, 0 ), QSizeF( 3, 3 ) );
Rect.moveCenter( QPointF( 0, 0 ) );
QPolygonF arrow( 3 );
arrow[ 0 ] = Rect.topLeft();
arrow[ 1 ] = QPointF( Rect.right(), 0 );
arrow[ 2 ] = Rect.bottomLeft();
painter->setBrush( Qt::black ); // fill with black on the arrow head
for ( int idx = 0; idx < dataSize; idx++ ) { // dataSize = 12,000
painter->save();
painter->translate( ... ) // translate to arrow location
painter->rotate( ... ) // rotate to angle degree depending on data
QLineF line( QPointF( 0, 0 ), QPointF( length, 0 ) ); // length is calculated from data
painter->drawLine( line );
painter->drawPolyon( arrow.translated( length, 0 ) );
painter->restore();
}
I need to draw 12,000 arrows pointing to different directions depending on data. It take very long time (about 1.5 seconds) to finish.
Following is the codes. If I comment out painter->drawPolyon(...), it only takes 0.037 seconds. Is there a way to speed it up? Thanks!
QRectF Rect( QPointF( 0, 0 ), QSizeF( 3, 3 ) );
Rect.moveCenter( QPointF( 0, 0 ) );
QPolygonF arrow( 3 );
arrow[ 0 ] = Rect.topLeft();
arrow[ 1 ] = QPointF( Rect.right(), 0 );
arrow[ 2 ] = Rect.bottomLeft();
painter->setBrush( Qt::black ); // fill with black on the arrow head
for ( int idx = 0; idx < dataSize; idx++ ) { // dataSize = 12,000
painter->save();
painter->translate( ... ) // translate to arrow location
painter->rotate( ... ) // rotate to angle degree depending on data
QLineF line( QPointF( 0, 0 ), QPointF( length, 0 ) ); // length is calculated from data
painter->drawLine( line );
painter->drawPolyon( arrow.translated( length, 0 ) );
painter->restore();
}