Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QCustomPlot: Performance of plot degrades massively when increasing pen width

QCustomPlot: Performance of plot degrades massively when increasing pen width

Scheduled Pinned Locked Moved Unsolved General and Desktop
qcustomplot
2 Posts 2 Posters 3.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    skebanga
    wrote on 14 Apr 2016, 20:20 last edited by skebanga
    #1

    I have a simple example app here which creates some random data (50 samples) and draws a line plot which has dragging enabled (full source code below)

    I have a single constant, PEN_WIDTH, which I change from a value of 1 to 2:

    const int PEN_WIDTH = 2;
    

    This constant is used in the call to QCPGraph::setPen

    QCPGraph* graph = plot.addGraph();
    graph->setPen(QPen(Qt::red, PEN_WIDTH));
    

    When using a PEN_WIDTH of 1, dragging is near instantaneous.
    When using a PEN_WIDTH of 2, dragging lags drastically, like several seconds.

    I can drag this with no perceptible delay:
    PEN_WIDTH=1
    Dragging this has a several second delay lag:
    PEN_WIDTH=2

    System specs:

    In case it has some bearing on the cause/solution, I am running this on Ubuntu 14.04 with Gnome 3 desktop. I have a 4-core Core i7-4790, am using onboard Xeon E3 graphics, and my system has 8GB RAM.

    Question:

    How can I have a larger pen width without sacrificing performance?

    Full example below:

    #include <QApplication>
    #include <QMainWindow>
    #include <qcustomplot/qcustomplot.h>
    #include <random>
    
    const int PEN_WIDTH   = 2;
    const int NUM_SAMPLES = 50;
    
    class Plot
    {
    public:
        Plot(int& argc, char** argv)
            : app(argc, argv)
        {
            window.setCentralWidget(&plot);
    
            plot.setInteractions(QCP::iRangeDrag);
            plot.axisRect()->setRangeDrag(Qt::Horizontal | Qt::Vertical);
    
            plot.xAxis->setTickLabelType(QCPAxis::ltDateTime);
            plot.xAxis->setDateTimeFormat("hh:mm:ss");
        }
    
        int exec()
        {
            std::random_device rd;
            std::mt19937 mt(rd());
            std::uniform_real_distribution<double> dist(0, 10);
    
            QVector<double> x,y;
            double i = 0;
            while (i < NUM_SAMPLES)
            {
                x.push_back(i);
                y.push_back(i * dist(mt));
                i += .1;
            }
    
            QCPGraph* graph = plot.addGraph();
            graph->setPen(QPen(Qt::red, PEN_WIDTH));
            graph->addData(x, y);
    
            plot.rescaleAxes();
            plot.replot();
    
            window.show();
            return app.exec();
        }
    private:
        QApplication app;
        QMainWindow  window;
        QCustomPlot  plot;
    };
    
    int main(int argc, char** argv)
    {
        return Plot(argc, argv).exec();
    }
    
    1 Reply Last reply
    0
    • P Offline
      P Offline
      Paul Colby
      wrote on 14 Apr 2016, 21:56 last edited by
      #2

      Just a small note for anyone else interested: there's some further discussion on this over on the QCustomPlot forums too.

      Cheers.

      1 Reply Last reply
      1

      1/2

      14 Apr 2016, 20:20

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved