This code is performant enough for me with up to 10.000 points:
{
public:
Plot()
{
for(int x=0;x<POINT_COUNT;x++)
data
[x
] = QPointF(qreal
(x
)/POINT_COUNT,
sin(x
/20.
));
}
{
painter.
setRenderHint(QPainter::Antialiasing);
painter.translate(0, height()/2);
painter.scale(width(), height()/2);
painter.setPen(Qt::darkGreen);
painter.setBrush(Qt::green);
painter.drawPolygon(data, POINT_COUNT);
}
static const int POINT_COUNT = 1000;
};
class Plot : public QWidget
{
public:
Plot()
{
for(int x=0;x<POINT_COUNT;x++)
data[x] = QPointF(qreal(x)/POINT_COUNT, sin(x/20.));
data[POINT_COUNT-1]=QPointF(1, 0);
}
void paintEvent(QPaintEvent*)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.translate(0, height()/2);
painter.scale(width(), height()/2);
painter.setPen(Qt::darkGreen);
painter.setBrush(Qt::green);
painter.drawPolygon(data, POINT_COUNT);
}
static const int POINT_COUNT = 1000;
QPointF data[POINT_COUNT];
};
To copy to clipboard, switch view to plain text mode
It will be faster without antialiasing of course.
If you want to speed it up more, you could use multiple threads that paint on QImages which are combined, or you could try painting on an OpenGL window.
But first of all I would try reducing complexity. How large is your rendering target? You don't need to use more than one point every two pixels or so.
Bookmarks