Hello,
I have a simple test program that plots 10 curves with 288 points each:
.h
{
public:
void drawCanvas
(QPainter* painter
) override
{
const auto start = std::chrono::system_clock::now();
const auto end = std::chrono::system_clock::now();
const auto dt = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
qDebug().nospace() << "dt = " << dt.count() << "ms";
}
};
class QwtPlotClient
: public QDialog{
Q_OBJECT
public:
QwtPlotClient
(QWidget* parent
= nullptr
);
private:
Ui::QwtPlotClientClass m_ui;
MyPlot* m_plot = nullptr;
};
class MyPlot : public QwtPlot
{
public:
void drawCanvas(QPainter* painter) override
{
const auto start = std::chrono::system_clock::now();
QwtPlot::drawCanvas(painter);
const auto end = std::chrono::system_clock::now();
const auto dt = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
qDebug().nospace() << "dt = " << dt.count() << "ms";
}
};
class QwtPlotClient : public QDialog
{
Q_OBJECT
public:
QwtPlotClient(QWidget* parent = nullptr);
private:
Ui::QwtPlotClientClass m_ui;
MyPlot* m_plot = nullptr;
};
To copy to clipboard, switch view to plain text mode
.cpp
namespace
{
std::vector<QVector<QPointF>> createPlotData(int curveCount = 10, int pointsPerCurve = 288)
{
std::vector<QVector<QPointF>> result;
std::default_random_engine engine(std::random_device{}());
std::uniform_real_distribution<double> distribution(-100.0, 100.0);
for (int curveIndex = 0; curveIndex < curveCount; curveIndex++)
{
QVector<QPointF> curvePoints;
double x = 0.0;
for (int point = 0; point < pointsPerCurve; point++)
{
curvePoints <<
QPointF(x, distribution
(engine
));
x += 2.0;
}
result.push_back(curvePoints);
}
return result;
}
}
QwtPlotClient
::QwtPlotClient(QWidget* parent
) m_plot(new MyPlot)
{
m_ui.setupUi(this);
m_ui.plotFrame->layout()->addWidget(m_plot);
const auto curvePointsList = createPlotData();
for (const auto& curvePoints : curvePointsList)
{
curve->setSamples(curvePoints);
curve->attach(m_plot);
}
}
namespace
{
std::vector<QVector<QPointF>> createPlotData(int curveCount = 10, int pointsPerCurve = 288)
{
std::vector<QVector<QPointF>> result;
std::default_random_engine engine(std::random_device{}());
std::uniform_real_distribution<double> distribution(-100.0, 100.0);
for (int curveIndex = 0; curveIndex < curveCount; curveIndex++)
{
QVector<QPointF> curvePoints;
double x = 0.0;
for (int point = 0; point < pointsPerCurve; point++)
{
curvePoints << QPointF(x, distribution(engine));
x += 2.0;
}
result.push_back(curvePoints);
}
return result;
}
}
QwtPlotClient::QwtPlotClient(QWidget* parent)
: QDialog(parent),
m_plot(new MyPlot)
{
m_ui.setupUi(this);
m_ui.plotFrame->layout()->addWidget(m_plot);
const auto curvePointsList = createPlotData();
for (const auto& curvePoints : curvePointsList)
{
auto* curve = new QwtPlotCurve();
curve->setSamples(curvePoints);
curve->attach(m_plot);
}
}
To copy to clipboard, switch view to plain text mode
In my main.cpp I define if the program uses high dpi settings or not:
int main(int argc, char *argv[])
{
// Comment the following 4 lines for NOT using high dpi settings
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round);
QwtPlotClient w;
w.show();
return a.exec();
}
int main(int argc, char *argv[])
{
// Comment the following 4 lines for NOT using high dpi settings
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QApplication a(argc, argv);
QwtPlotClient w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
As you can see I measure the time that the qwt plot needs for drawing the canvas (see MyPlot::drawCanvas). The results are (on my computer, you probably will have different absolute values):
High dpi settings off: ~25ms (for Debug) / ~10ms (for Release)
High dpi settings on: ~800ms ms (for Debug) / ~570ms (for Release)
I tested this with Qt 5.14.0 and Qwt 6.2.1. (I also tested with Qwt 6.2.0 and the numbers for high dpi settings on are even a bit larger.)
Is there anything I can do? Or do you plan to "fix" this in the near future?
Bookmarks