Hi,
I currently have a problem with line drawing in QPainter. I draw "only" simple 2000 lines but it takes something like 50ms for each update. My problem is all the lines continuously move to draw a nice slowly rotating graph (note : it's not just a rotate()).
To check I run the following code only :
{
QElapsedTimer chronoPainter;
const int cst_nbLines = 5000;
chronoPainter.start();
for (int i=0 ; i<cst_nbLines ; i++)
{
QLine myLine
(i
/10, i
/10, i
/10+300, i
/10);
myPainter.drawLine(myLine);
}
qint64 elapsed_ns = chronoPainter.nsecsElapsed();
qint64 elapsed_ms = elapsed_ns/1000000L;
qDebug() << "End, time to paint : " << elapsed_ms << "ms";
}
void Widget::paintEvent(QPaintEvent *event)
{
QElapsedTimer chronoPainter;
QPainter myPainter(this);
const int cst_nbLines = 5000;
chronoPainter.start();
for (int i=0 ; i<cst_nbLines ; i++)
{
QLine myLine(i/10, i/10, i/10+300, i/10);
myPainter.drawLine(myLine);
}
qint64 elapsed_ns = chronoPainter.nsecsElapsed();
qint64 elapsed_ms = elapsed_ns/1000000L;
qDebug() << "End, time to paint : " << elapsed_ms << "ms";
}
To copy to clipboard, switch view to plain text mode
And drawing my 2000 very simple lines takes... 50ms. Not way to have a 50FPS animation with that. Have you got an idea of how I can draw all the lines faster?
I've tried with
QVector<QLine> linesVector;
for (int i=0 ; i<cst_nbLines ; i++)
{
linesVector.
append(QLine(i
/10, i
/10, i
/10+300, i
/10));
}
myPainter.drawLines(linesVector);
QVector<QLine> linesVector;
for (int i=0 ; i<cst_nbLines ; i++)
{
linesVector.append(QLine(i/10, i/10, i/10+300, i/10));
}
myPainter.drawLines(linesVector);
To copy to clipboard, switch view to plain text mode
but it not helps (same drawing time).
Thank you!
Bookmarks