在QwtPlot中使用QTime作为X asis
Using QTime as X asis in QwtPlot
我正在尝试使用qwtplot绘制速度-时间图形。
我的X数据是QTime值,Y数据是相应的速度值。我找不到任何关于用QTime绘制绘图的例子。有人能简单地解释一下如何绘制QTime与Y的数据吗?如果可能的话,我也想学习如何缩放QTime轴。
感谢HeyYO,我为未来的读者找到了解决方案。我分享一个非常简单的例子:
#include "QApplication"
#include<qwt_plot_layout.h>
#include<qwt_plot_curve.h>
#include<qwt_scale_draw.h>
#include<qwt_scale_widget.h>
#include<qwt_legend.h>
class TimeScaleDraw:public QwtScaleDraw
{
public:
TimeScaleDraw(const QTime & base)
:baseTime(base)
{
}
virtual QwtText label(double v)const
{
QTime upTime = baseTime.addSecs((int)v);
return upTime.toString();
}
private:
QTime baseTime;
};
int main(int argc,char * argv[])
{
QApplication a(argc,argv);
QwtPlot * myPlot = new QwtPlot(NULL);
myPlot->setAxisScaleDraw(QwtPlot::xBottom,new TimeScaleDraw(QTime::currentTime()));
myPlot->setAxisTitle(QwtPlot::xBottom,"Time");
myPlot->setAxisLabelRotation(QwtPlot::xBottom,-50.0);
myPlot->setAxisLabelAlignment(QwtPlot::xBottom,Qt::AlignLeft|Qt::AlignBottom);
myPlot->setAxisTitle(QwtPlot::yLeft,"Speed");
QwtPlotCurve * cur = new QwtPlotCurve("Speed");
QwtPointSeriesData * data = new QwtPointSeriesData;
QVector<QPointF>* samples=new QVector<QPointF>;
for ( int i=0;i<60;i++)
{
samples->push_back(QPointF(i,i*i));
}
data->setSamples(*samples);
cur->setData(data);
cur->attach(myPlot);
myPlot->show();
return a.exec();
}
相关文章:
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 将Ref对象作为类成员
- 虚拟决赛作为安全
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 使用指向成员的指针将成员函数作为参数传递
- 我应该使用什么来代替void作为变体中的替代类型之一
- 何时提供默认参数作为模板参数
- 如何将 I->getType() 作为参数传递给 llvm 中的 CreateCall?
- C++使用数组作为多维数组,尽管将其初始化为带有指针的 1D
- C++匿名结构作为std::映射值
- C++:如何使函数只返回作为列表一部分的字符串
- 如何制作一个将函数作为参数的类方法
- 如何在C++中使用非静态成员函数作为回调函数
- 修改函数中的指针(将另一个指针作为参数传递)
- Clang bug?使用指针作为模板参数
- 函数作为模板参数,是否对返回类型强制约束
- 在C++中传递给函数时,为什么要指定数组大小作为参数
- 为什么 Clang 不允许"and"作为函数名称?
- 在QwtPlot中使用QTime作为X asis