0

当使用 QtChart 库绘制小范围内的线系列时(例如,0 到 1e-15 之间),线系列似乎不会被渲染。使用具有相同确切代码的更大数字非常有效。

我已经尝试将我的代码简化为尽可能简单,以找出我所犯的任何错误,但我找不到任何错误。我怀疑这可能是 Qt 中的一个错误,但我在这里发布,以防我在提交错误报告之前错过了一些东西。

我也没有在网上找到任何关于遇到类似错误的人的信息,但这可能只是表明我的 google-fu 很弱。

我最初使用 PyQt5 遇到了这个错误,但在 C++ 中重新创建了它以确保它不是 PyQt5 特定的错误。

#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
#include <QtCharts/QLegend>
#include <QtCharts/QValueAxis>

QT_CHARTS_USE_NAMESPACE

#define FACTOR 1e-13

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QLineSeries *lineseries = new QLineSeries();
    lineseries->setName("series");
    lineseries->setUseOpenGL(true);

    for (double i = 0.0; i < 10.0; i += 1.0)
        lineseries->append(QPointF(i*FACTOR, i * FACTOR));

    QChart *chart = new QChart();
    chart->addSeries(lineseries);
    chart->setTitle("Line example");

    QValueAxis *axisX = new QValueAxis();
    chart->setAxisX(axisX, lineseries);

    QValueAxis *axisY = new QValueAxis();
    chart->setAxisY(axisY, lineseries);
    axisY->setRange(0.0, 9.0*FACTOR);

    axisX->setLabelFormat("%.3E");
    axisY->setLabelFormat("%.3E");

    chart->legend()->setVisible(true);
    chart->legend()->setAlignment(Qt::AlignBottom);

    QChartView *chartView = new QChartView(chart);
    chartView->setRenderHint(QPainter::Antialiasing);

    QMainWindow window;
    window.setCentralWidget(chartView);
    window.resize(840, 900);
    window.show();

    return a.exec();
}

运行附加的代码,我希望观察到图中呈现的线性线系列,但我没有看到任何呈现。

将常量修改为FACTOR>= 1e-12 将使线系列正确显示。

4

0 回答 0