Qwt教程翻译:第4章-例图和轴标题,Chapter 4 - Legend and Axis Titles
原文: http://www.thewireframecommunity.com/node/45
发表于2010 年5月 10 日,星期一,9:27 , 作者Uditha Atukorala
注意 : 请注意,现在qwt 的所有的包含头文件有了qwt/前缀 ,例如 #include <qwt/qwt_plot.h> 。如果你是按照第1 章的步骤来的 ,那么你不需要那个前缀。
在这一章中我们将会添加图表图 例和轴标题 ,并且会改变我们的简单Qwt 图表的背景颜色 。
我们将会在我们的代码里添加一个新的方法,叫做setupPlot()。这将会使得我更容易讲解每一步 ,并且在需要的时候很方便地进行引用 。另外 ,将你的代码分解成小的可管理的段落也是一种好的做法 。
改变widget.h,添加新的void setupPlot()方法
。
代码清单4.1-1 (widget.h)
private:
Ui::Widget *ui;
void setupPlot();
};
我们会在构造函数里调用这个方法。将widget.cpp 改成下面这样的
。
代码清单4.1-2 (widget.cpp)
#include "widget.h"
#include "ui_widget.h"
#include <qwt/qwt_legend.h>
Widget::Widget(QWidget *parent) : QwtPlot(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
this->setupPlot();
}
Widget::~Widget()
{
delete ui;
}
void Widget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void Widget::setupPlot() {
this->setTitle("Qwt Tutorial");
this->setCanvasBackground(QColor(Qt::white));
this->setAutoReplot(false);
this->setMargin(5);
// legend
QwtLegend *legend = new QwtLegend;
legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
this->insertLegend(legend, QwtPlot::BottomLegend);
// axis
this->setAxisTitle(QwtPlot::xBottom, "X Axis");
this->setAxisTitle(QwtPlot::yLeft, "Y Axis");
}
使用上面的setupPolt()方法,我们简单地将标题设为Qwt Tutorial,将背景颜色设为白色。即使我们在这里设置了图例 ,你仍然不会看到任何效果。我们稍后将讲到图例 。
我们还设置了X 轴和Y 轴的文字。
图4.3-1
附件 |
大小 |
21.6 KB |
HxLauncher: Launch Android applications by voice commands