Important: Please read the Qt Code of Conduct -

Painting on qimage or qpixmap taking time in real time plotting

  • if i plot ECG graph on qimage or qpixmap, i wont get proper heart beat (for 180 i will get 237 --- data is missing, painting taking time). If i comment draw graph, i am getting proper heart beat value. How to synchronize my application with graph. Which method makes less time consume.

    Thanks in advance...

  • You should provide some code, it seems that you are doing something wrong as it should not take a lot of time to draw a simple graph (basically just put some pixels). the thing you can try is to separate reading a storing data from drawing graph into different threads.

    BTW if heartbeat is 237 instead of 180 doesn't it meant that a graph is kind of being drawn FASTER then it should be? maybe you just messed with an x axis

  • from one thread i am getting ecg data through SPI and writing to pipe, calculating heart beat value . on another thread i am reading from that pipe and giving signal to slot. in slot i am calling DrawECG function which has painting things.
    in GUI (ui) i have qlable--ANSiscope_Graph_label

    in constructor i am declaring painter and pixmap

    ECGImagePainter = new QPainter;
    ecgpixmap = new QPixmap(236,97);

    in DrawECG(int data) function i am plotting ECG graph
    firstTimeECG = 0;

        ECGgraph.Ypos = (ECGgraph.rightbottom.Y - ECGgraph.lefttop.Y) - (ECGgraph.Yunit * (data - ECGgraph.lYMin));
        ECGgraph.currentplot.Y=(int)ECGgraph.Ypos  ;
        if(ECGgraph.currentplot.X >= ECGgraph.rightbottom.X)
            ECGgraph.currentplot.X = 0;
            ECGgraph.lastplot.X = 0;
        ECGgraph.lastplot.X = ECGgraph.currentplot.X;
        ECGgraph.lastplot.Y = ECGgraph.currentplot.Y;


    two threads are in while(1), switching by sched_yield()

    if i comment drawECG function in slot i will get proper results. if i plot ecg, ill get improper heart beat value.

    calling once setpixmap statement in a drawecg function, i will get result but no graph on screen.

    which is a real time plotting 1200 samples per second

    [EDIT: code formatting, please wrap in @-tags, Volker]

  • Best piece of advice: Don't try plotting at 1200 Hz. Gather your data and draw at a maximum of 60 Hz. 30 Hz may even be sufficient for proper data. Don't assume the operating system will provide you with the timing you need. As long as you're sure you get all your data, store it somewhere until the next drawing moment has arrived. Getting real-time graphs is all about knowing when not to draw.

    You can also optimize your drawing a bit by queueing up all lines you are going to draw, and feed them to QPainter::drawLines(), which is best practice in doing your own drawing anyway.

  • Greetings sushmars,

    I am working on a similar task these days - trying to accomplish best quality plot for ECG signal from signals database.

    Have you succeed to plot the data as required ?

    Can you share the code for your application ? ( here or in private message )

    If not, could that be purchased if yes how much does it cost ?


Log in to reply