StupidBeauty
Read times:1778Posted at:Wed Dec 1 10:25:12 2010 - no title specified

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 图表的背景颜色

4.1 - setupPlot()方法

我们将会在我们的代码里添加一个新的方法,叫做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");

}

4.2 - 解释

使用上面的setupPolt()方法,我们简单地将标题设为Qwt Tutorial,将背景颜色设为白色。即使我们在这里设置了图例 ,你仍然不会看到任何效果。我们稍后将讲到图例

我们还设置了X 轴和Y 轴的文字

4.3 - 最终输出

Qwt Plot

图4.3-1

附件

大小

qwt教程第 4 章.tar.gz

21.6 KB

Your opinions

Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands

 
Recent comments
2017年4月~2019年4月垃圾短信排行榜Posted at:Thu Sep 26 04:51:48 2024
Qt5.7文档翻译:QWebEngineCookieStore类,QWebEngineCookieStore ClassPosted at:Fri Aug 11 06:50:35 2023盲盒kill -9 18289 Grebe.20230517.211749.552.mp4