Optimized Line drawing in QT -
i new qt. working on graphics.
i using qwidget drawing graphics(for drawing graphics in qwidget paint event). need draw background , foreground graphics. background fixed graphics. foregrounds drawing lines.
each 100 millisecond need draw 20points. drawing time 8 sec. total need draw 1600 points (total points represents contentious line).
i using qtimer invoke drawing in each 100ms. first few drawing drawn fast. in middle of drawing it's become slow.
the problem need draw foreground , background in each 100ms.
please me fix problem. if 1 have sample code please provide. in advance.
is there way draw partial area ie. particular modified region of graphics?
qpainter-drawing can slow without hardware support. using qgraphicsview won't if lines visible, since internally uses qpainter anyway.
if have draw 20 new points (or lines) per update , per update background gets cleared have render again, there few things try:
1) disable background autofill. see: qwidget::autofillbackground add widget init:
setautofillbackground(false); setattribute(qt::wa_opaquepaintevent, true); setattribute(qt::wa_nosystembackground, true);
now on first update render background , first lines. next updates skip rendering background , render new lines.
2) use double buffering. example, create qimage of size of widget.
.h private: qimage m_targetimage; .cpp // constructor m_targetimage = qimage(width(), height(), qimage::format_argb32); // paint event // draw image qpainter p; p.begin(&m_targetimage); static bool firstupdate = true; if (firstupdate) { // draw background) p.drawimage(...); firstupdate = false; } // draw latest lines p.drawlines(....); p.end(); // draw image in widget paint qpainter painter; painter.begin(this); painter.drawimage(0, 0, m_targetimage); painter.end();
3) use qglwidget if possible. inherit widget qglwidget instead of qwidget. method doesn't work on platforms , speed increase might not enough. using opengl brings kind of new problems.
Comments
Post a Comment