qt5 QCharts使用 繪製曲線步驟

2021-07-30 15:19:41 字數 2276 閱讀 4148

step:

qt       += core gui sql  charts
2. 建立qchartview只需在生成的mainwindow.cpp中新增以下四行**,就完成了qchartview的建立。

#include "mainwindow.h"

#include "ui_mainwindow.h"

#include // 手動新增**行1

using namespace qtcharts; // 手動新增**行2

mainwindow::mainwindow(qwidget *parent) :

qmainwindow(parent),

ui(new ui::mainwindow)

mainwindow::~mainwindow()

現在我們已經完成了,qchartview的建立,編譯並執行,可以看到如下效果,白色部分就是我們建立的chartview,什麼也沒有是因為我們沒有在上邊新增series.

如果在*.ui中拖拽也可以完成qchartview建立工作,不過需要prompt.

我一般是在程式裡直接**建立widget(這樣做的好處是便於版本管理,當然這只是個人習慣)。

3. 繪製曲線,新增資料

這裡我們給chart新增一條曲線:

#include "mainwindow.h"

#include "ui_mainwindow.h"

#include #include using namespace qtcharts;

mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent),ui(new ui::mainwindow)

_chart_view->chart()->addseries(seriesx);

}

mainwindow::~mainwindow()
效果如下:

4. 其他屬性

#include "mainwindow.h"

#include "ui_mainwindow.h"

#include #include #include using namespace qtcharts;

mainwindow::mainwindow(qwidget *parent) :

qmainwindow(parent),

ui(new ui::mainwindow)

/* 其他屬性的設定 */

_chart_view->chart()->addseries(seriesx);

_chart_view->chart()->settheme(qchart::chartthemebluecerulean);

seriesx->setname("test data");

_chart_view->chart()->settitle("chart for test");

qvalueaxis *axisx = new qvalueaxis;

axisx->settitletext("sample time(s)");

_chart_view->chart()->setaxisx(axisx, seriesx);

qvalueaxis *axisy = new qvalueaxis;

axisy->settitletext("height(meter)");

_chart_view->chart()->setaxisy(axisy,seriesx);

_chart_view->chart()->legend()->setvisible(true);

_chart_view->chart()->legend()->setalignment(qt::alignbottom);

}mainwindow::~mainwindow()

效果如下:

YOLOV3實戰5 利用三方工具繪製P R曲線

二 指令碼檔案說明 進入根目錄,依次進入 submodules kittiobjective2 此時目錄下一共6個物件 1 val gt資料夾儲存樣本的標籤文件,開啟000000.txt舉例說明其組織格式 pedestrian 0.00 1 0.30 883.68 144.15 937.35 259...

使用HTML5 Canvas API繪製弧線的教程

繪製標準圓弧 在開始之前,我們優化一下我們的作圖環境。靈感來自於上節課的紋理,如果不喜歡這個背景,我在images目錄下還提供了其他的背景圖,供大家選擇。另外把所有的樣式表都寫在了 下。j ascript code複製內容到剪貼簿 執行結果 之所以要繪製乙個空白的矩形填滿畫布,是因為我們之前說過,c...

Qt5編譯使用QFtp

git clone 完成之後,可以看到 qtftp 中包含原始碼及示例。下面,以 msvc為例。開啟 qtftp.pro,將預設配置 config static config shared 改為 config staticlib config shared 這樣,生成 dll的同時也會生成 lib。...