- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我需要在程序测试期间创建一系列绘图。我想为此目的使用 QCustomPlot
,但我遇到了问题。为了在文件中创建和保存我的绘图,我必须创建 QApplication
,在我需要从 QMainWindow
重新实现我的类之后,我可以使用我的 QCustomPlot
在创建所有需要的绘图并将它们保存到文件的函数中。是否可以避免创建 QApplication
实例或 QMainWindow
实例或两者?
请参阅下面我的函数代码:
void MainWindow::print_image(std::vector<double> az, std::vector<double> el, std::vector<double> za, char *image_path){
QVector<double> azFunct;// =// QVector<double>::fromStdVector(az);
QVector<double> elFunct;// =// QVector<double>::fromStdVector(el);
QVector<double> zFunct = QVector<double>::fromStdVector(za);
QVector<double> xAxisValue(az.size());
//Filling axes of x with values
std::iota(xAxisValue.begin(),xAxisValue.end(),0);
QCustomPlot customPlot;
customPlot.setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // period as decimal separator and comma as thousand separator
customPlot.legend->setVisible(true);
QFont legendFont = font(); // start out with MainWindow's font..
legendFont.setPointSize(9); // and make a bit smaller for legend
customPlot.legend->setFont(legendFont);
customPlot.legend->setBrush(QBrush(QColor(255,255,255,230)));
// by default, the legend is in the inset layout of the main axis rect. So this is how we access it to change legend placement:
customPlot.axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignRight);
//Adding new graph for displaying, all on the same plot.
customPlot.addGraph(customPlot.yAxis, customPlot.xAxis);
customPlot.graph(0)->setPen(QPen(QColor(255, 100, 0)));
customPlot.graph(0)->setName("Azimuth function");
//Adding new graph for displaying, all on the same plot.
customPlot.addGraph();
customPlot.graph(1)->setPen(QPen(Qt::red));
customPlot.graph(1)->setName("Elevation function");
//Adding new graph for displaying, all on the same plot.
customPlot.addGraph();
customPlot.graph(2)->setPen(QPen(Qt::green));
customPlot.graph(2)->setName("Z-axis function");
for(int i = 0; i < az.size(); ++i){
azFunct[i] = sin(az[i]*M_PI/180);
elFunct[i] = cos(el[i]*M_PI/180);
}
double minZ = *std::min_element(zFunct.constBegin(), zFunct.constEnd());
double maxZ = *std::max_element(zFunct.constBegin(), zFunct.constEnd());
// pass data points to graphs:
customPlot.graph(0)->setData(xAxisValue, azFunct);
customPlot.graph(1)->setData(xAxisValue, elFunct);
customPlot.graph(2)->setData(xAxisValue,zFunct);
customPlot.xAxis->setVisible(true);
customPlot.xAxis->setTickLabels(false);
customPlot.xAxis2->setVisible(true);
customPlot.xAxis2->setTickLabels(false);
customPlot.yAxis2->setVisible(true);
// set ranges appropriate to show data:
customPlot.yAxis->setRange(-1, 1);
customPlot.yAxis2->setRange(minZ, maxZ);
customPlot.plotLayout()->insertRow(0);
//customPlot.plotLayout()->addElement(0, 0, new QCPTextElement(customPlot, "Z axis", QFont("sans", 12, QFont::Bold)));
// set labels:
customPlot.yAxis->setLabel("sin/cos value");
customPlot.yAxis2->setLabel("Z - axis");
//Under big question have to be tested!
customPlot.replot();
customPlot.savePng(QString(image_path),1500,500,1);}
最佳答案
当然你不需要QMainWindow
,你可以自己实例化一个QCustomPlot
实例,而不是作为其他任何东西的子部件。此外,您无需显示该小部件即可绘制它。因此测试可以是非交互式的,即使它们实例化了 QApplication
。
当然,QCustomPlot
的设计是坏的;没有必要让它成为 QWidget
。只有绘图的特定 View 需要成为小部件。但那是另一回事了。
关于c++ - 是否可以在单元测试中使用 QCustomPlot?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51336336/
说明 使用 QCustomPlot 绘图库辅助开发时整理的学习笔记。同系列文章目录可见 《绘图库 QCustomPlot 学习笔记》目录 。本篇介绍 QCustomPlot 帮助文档的配置
说明 使用 QCustomPlot 绘图库辅助开发时整理的学习笔记。同系列文章目录可见 《绘图库 QCustomPlot 学习笔记》目录 。本篇介绍 QCustomPlot 的一种使用方法
我用qcustomplot来画item。 我有两个项目。一个是项目文本,另一个是项目矩形。 我想做的是当我选择文本时,项目矩形改变颜色。 我已经使用 itemAt 来检查鼠标是否点击了一个项目。 但是
我正在开发一个带有绘图的简单 GUI,您可以在其中设置一些 x 和 y 范围。我如何从绘图上所有图形中选择这些范围内的所有项目?我试图重现在 mouse rectangular multi range
我是 QCustomPlot 的新手,想开始第一个关于基本用法的 QCustomPlot 示例。在下面的代码中:我总是有一个断点,它在程序即将调试时停止程序(没有错误并且构建成功完成) QCustom
我需要在程序测试期间创建一系列绘图。我想为此目的使用 QCustomPlot,但我遇到了问题。为了在文件中创建和保存我的绘图,我必须创建 QApplication,在我需要从 QMainWindow
我正在尝试使用上下文菜单将新的 sub-axes 图添加到现有的 qcustomplot 小部件。如果我在类构造函数中调用我的 _addGraph 函数,它会按预期工作。但是,如果我将它用作 slot
我正在使用 QCustomPlot 并在屏幕上绘制了多个图形,我希望能够单击并指向然后能够获取我单击的点的数据或坐标等上,我知道这对于使用 QCP::iSelectPlottables 的整个图本身是
使用 QT 的 QCustomPlot 插件。我不得不绘制可能非线性的点,因此图形可能看起来像这样 结果如何 但这是显示的内容 使用这段代码 plotter->addGraph();
使用 qcustomplot 创建绘图后,如何根据现有的 X 值检索 Y 值,然后在这些位置绘制点? 我的尝试如下: 创建情节: 此函数创建一个绘图,在 x 轴上添加一些数据(日期)并在 y 轴上添加
我想问一个关于qcustomplot的问题。如何根据 Slider 更改 itemLine 位置? (比如 x = a) #include "itemline.h" #include "ui_item
我使用 QCustomPlot 来显示图片的直方图。我用来设置曲线的函数如下: void SingleHistogram::setHist(const QVector &x,
QCustomPlot 具有接受 const 变量的 setData 函数。有没有办法让 QCustomPlot 可以用来动态绘图?QCustomPlot setData 函数接受常量 vector
说明 使用 QCustomPlot 绘图库辅助开发时整理的学习笔记。同系列文章目录可见 《绘图库 QCustomPlot 学习笔记》目录 。本篇介绍如何使用 QCustomPlot 绘制
有没有办法在隐藏网格的同时在 QCustomPlot 中显示零线?我尝试用以下行隐藏网格: ui->customPlot->xAxis->grid()->setVisible(false); ui->
我想绘制每 100 毫秒出现的大量数据 (3k)。我试过 QCustomPlot和 Qwt精确的 3k 点,我在使用 Qwt 绘图时表现非常好,而使用 QCustomPlot 时表现非常糟糕。我认为我
我成功地在 visual studio 2012 中构建了一个程序,该程序在没有插件的情况下运行 QT。我包含了 QT include 文件夹并手动将库添加到资源中。然后它编译并运行。 现在我想以相同
我目前正在开发一个实时绘制来自 ADC 的数据的应用程序。在某些情况下,我必须绘制大约 150k 个点,这需要一些时间。所以问题是数据到达的频率可能比我能够绘制的频率更高。 我不需要高帧率。我也可以努
我使用 Windows 7 x64、Qt 5.6、Visual Studio 2015、QCustomPlot 1.3.2。我需要从传感器(实时)绘制温度图。我每 500 毫秒接收一次温度值(频率 =
我正在尝试将文本项添加到 QCustomPlot 上小部件。 QCPItemText构造函数接受一个指向 QCustomPlot 的指针小部件作为参数。 QCPItemText::QCPItemTex
我是一名优秀的程序员,十分优秀!