mirror of
https://github.com/chengyangkj/Ros_Qt5_Gui_App.git
synced 2025-09-15 12:58:58 +08:00
添加qchart绘图
This commit is contained in:
parent
27762f03e2
commit
14ff321f8b
@ -27,6 +27,9 @@
|
||||
#include <QVariant>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QtCharts>
|
||||
#include <QTimer>
|
||||
#include <QQueue>
|
||||
#include <map>
|
||||
#include <QtWebEngineWidgets/QWebEngineSettings>
|
||||
#include "./include/cyrobot_monitor/animationstackedwidget.h"
|
||||
@ -56,6 +59,7 @@ public:
|
||||
void initUis();
|
||||
void initVideos();
|
||||
void initTopicList();
|
||||
void initCharts();
|
||||
public slots:
|
||||
/******************************************
|
||||
** Auto-connections (connectSlotsByName())
|
||||
@ -102,6 +106,7 @@ public slots:
|
||||
void slot_closeWindows();
|
||||
void slot_minWindows();
|
||||
void slot_maxWindows();
|
||||
void slot_chartTimerTimeout();
|
||||
// void on_horizontalSlider_raw_valueChanged(int value);
|
||||
private slots:
|
||||
|
||||
@ -140,6 +145,18 @@ private:
|
||||
QGraphicsScene *m_qgraphicsScene=NULL;
|
||||
roboMap *m_roboMap=NULL;
|
||||
QVariantList m_sendVelList,m_recvVelList,m_timeList;
|
||||
//曲线
|
||||
QSplineSeries* line;
|
||||
//曲线点的最大数量
|
||||
int line_max = 10;
|
||||
//绘图变量和坐标
|
||||
QChart* chart;
|
||||
QValueAxis *axisX;
|
||||
QValueAxis *axisY;
|
||||
QQueue<QPointF> data1;
|
||||
QQueue<QPointF> data2;
|
||||
QTimer *m_timerChart;
|
||||
QChartView *chartView;
|
||||
};
|
||||
}// namespace cyrobot_monitor
|
||||
|
||||
|
||||
@ -131,6 +131,7 @@ void MainWindow::initUis()
|
||||
ui.close_btn->setIcon(QIcon("://images/close.png"));
|
||||
rock_widget =new JoyStick(ui.JoyStick_widget);
|
||||
rock_widget->show();
|
||||
initCharts();
|
||||
}
|
||||
|
||||
void MainWindow::connections()
|
||||
@ -213,6 +214,69 @@ void MainWindow::slot_hide_table_widget(){
|
||||
ui.table_hide_btn->setStyleSheet("QPushButton{background-image: url(://images/show.png);border:none;}");
|
||||
}
|
||||
}
|
||||
void MainWindow::initCharts(){
|
||||
line = new QSplineSeries(this);
|
||||
chart = new QChart();
|
||||
chart->addSeries(line);
|
||||
axisX = new QValueAxis(this);
|
||||
axisY = new QValueAxis(this);
|
||||
|
||||
chartView = new QChartView(ui.widget_chart);
|
||||
chartView->setFixedWidth(ui.widget_chart->width());
|
||||
chartView->setFixedHeight(ui.widget_chart->height());
|
||||
chartView->setRenderHint(QPainter::Antialiasing);
|
||||
m_timerChart=new QTimer;
|
||||
m_timerChart->setInterval(100);
|
||||
connect(m_timerChart,SIGNAL(timeout()),this,SLOT(slot_chartTimerTimeout()));
|
||||
m_timerChart->start();
|
||||
}
|
||||
void MainWindow::slot_chartTimerTimeout(){
|
||||
QVector<QPointF> list;
|
||||
QVector<QPointF> newlist;
|
||||
list = line->pointsVector();//获取现在图中列表
|
||||
if (list.size() < line_max)
|
||||
{
|
||||
//保持原来
|
||||
newlist = list;
|
||||
}
|
||||
else
|
||||
{
|
||||
//错位移动
|
||||
for(int i =1 ; i< list.size();i++)
|
||||
{
|
||||
newlist.append(QPointF(i-1,list.at(i).y()));
|
||||
}
|
||||
}
|
||||
newlist.append(QPointF(newlist.size(),rand()));//最后补上新的数据
|
||||
line->replace(newlist);//替换更新
|
||||
|
||||
|
||||
line->setName("send");//设置曲线名称
|
||||
line->setPen(QColor(255, 0, 0));//设置曲线颜色
|
||||
line->setUseOpenGL(true);//openGl 加速
|
||||
|
||||
chart->setTitle("Pressure Data");//设置图标标题
|
||||
chart->removeSeries(line);
|
||||
chart->addSeries(line);
|
||||
chart->createDefaultAxes();//设置坐标轴
|
||||
|
||||
// axisX->setRange(0,line_max);//范围
|
||||
// axisX->setTitleText("times(secs)");//标题
|
||||
axisX->setTickCount(10);//分隔个数
|
||||
axisX->setLineVisible(true);//可视化
|
||||
axisX->setLinePenColor(Qt::blue);//颜色
|
||||
|
||||
// axisY->setRange(-200,1200);
|
||||
// axisY->setTitleText("value");
|
||||
// axisY->setTickCount(6);
|
||||
// axisY->setLineVisible(true);
|
||||
// axisY->setLinePenColor(Qt::blue);
|
||||
|
||||
// chart->setAxisX(axisX,line);
|
||||
// chart->setAxisY(axisY,line);
|
||||
|
||||
chartView->setChart(chart);
|
||||
}
|
||||
//设置界面
|
||||
void MainWindow::slot_setting_frame()
|
||||
{
|
||||
|
||||
@ -31,12 +31,30 @@ padding:0</string>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_25">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_16">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_3" native="true">
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_15">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
@ -287,12 +305,26 @@ padding:0</string>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QWidget{
|
||||
background-color:rgb(67, 154, 246);
|
||||
padding:0;
|
||||
}</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_24">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_14">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_dash">
|
||||
<property name="minimumSize">
|
||||
@ -319,6 +351,8 @@ background-color:green
|
||||
QPushButton{
|
||||
background-color:rgb(67, 154, 246);
|
||||
border:none;
|
||||
padding:0px 0px 0px 0px;
|
||||
margin:0px 0px 0px 0px;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
@ -361,6 +395,8 @@ background-color:green
|
||||
QPushButton{
|
||||
background-color:rgb(67, 154, 246);
|
||||
border:none;
|
||||
padding:0px 0px 0px 0px;
|
||||
margin:0px 0px 0px 0px;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
@ -605,6 +641,19 @@ border:none;
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QWidget" name="widget_chart" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>400</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px solid rgb(0, 0, 0)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user