当前位置:网站首页>With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate
With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate
2022-04-23 18:19:00 【Things will turn when they reach the extreme 1024】
It's done , But it's troublesome to transplant later , No longer use this method , change to the use of sth.
https://blog.csdn.net/qq_27620407/article/details/108734088 such
Let's take a look at the preview , Just finished writing callout, So it highlights this , Let's start describing the functions one by one .

Qchart I read some articles on this one , Is to integrate various functions you need into your own classes . Inheritance didn't learn well , This is really hard for me , Other difficulties are how to realize the functions of each part , This is relatively easy to find by searching .
Class structure :
Mychart–>Callot–>Mychart
|______________|
Because of my C++ Inheritance is not very good , The convenience of inheritance will be a little messy .
● It's basically the first step Mychart Inherit QChart, Then add some of your own content .
●Callout Use Mychart Instead of using it directly QChart Because , hold Call Oh, my God MychartView when , I wrote it myself connect There is no way to hide the dialog box of coordinates after the mouse leaves , Will always show , Only use other people's structures .
Callout Inheritance is QGraphicsItem, This class can directly copy the... In the official routine Callout file , Then make some changes , That's what I did .
● Then is MychartView, This is more difficult , It is also a point of my overall transformation of thinking . This one says , take your time .
Mychart
First, the parent class QChart, After the configuration of this class is completed, a show Function can directly display a curve , This curve contains the curve itself 、 Axis 、 Grid in background 、 Legend, etc , In this case, I use these functions .
Let's start constructing this first class , After the implementation of this class, you can use QChartView Call the custom class to realize the above functions , although Qchart The same effect can be achieved , But this class is simple , Let's practice first .
from H The document says
Variable :
// It's necessary
QLineSeries *m_series; // Curve data
QList<QLineSeries *> m_serieslist; // Curve list ,splineseries Is a smooth curve QLineSeries Broken line
int m_SeriesNum; // Number of curves
QChart *m_Chart; // Show
// Non essential
QStringList m_titles; // title
// The following is for the coordinate axis
QValueAxis *axisX; //x Axis
QValueAxis *axisY; //y Axis
qreal m_x;
qreal m_y;
// The coordinate axis is used for automatic adjustment
int m_Max_AllValue; // Maximum value of all images
int m_Min_AllValue; // Minimum value of all images
QList<qreal *> m_Max_Ser;// The maximum value of each image
QList<qreal *> m_Min_Ser;// Minimum value of each image
QList<qreal *> m_SectionMax_Ser;// Maximum value of image interval
QList<qreal *> m_SectionMin_Ser;// Minimum value of image interval
QList<int *> m_axisXMax;// Number of data per image
There are some useless variables , Consider this for yourself , Talk about the more important .
1、QChart *m_Chart;
This will replace... In future use Mychart As a real substitute QChart, This is what I didn't think of at first , Lead to the back Mychart Really Qchart Use , Wasted a lot of effort , It can also be seen from this that , The class I define now is actually in the original QChcart On the basis of a shell , This class can implement Qchart All functions of , With some pairs of Qchart The operation of ,m_Chart Is the body of the curve .
, Here I recommend the article I read at that time , You'd better look directly at , Don't look at my
https://blog.csdn.net/qq_31073871/article/details/82987524
Here to Qchart The use of is very good , Novices can get it out directly .
2、 QLineSeries *m_series; and QList<QLineSeries *> m_serieslist;
QLineSeries *m_series; // Curve data
QList<QLineSeries *> m_serieslist; // Curve list ,splineseries Is a smooth curve QLineSeries Broken line
m_series Is actually displayed , The curve is m_series, Other background axes are Qchart The content of .
The first premise of displaying the curve , take m_series Add to Qchart in , The second one is for m_series Write data .
Join only once , Then you can give m_series Write data ,Qchart It will update automatically .
m_series Add to Qchart in : m_Chart->addSeries(m_series);
to m_series Write data :m_series->append(x,y);
m_series In practical use, it is generally used QList<QLineSeries *> m_serieslist Instead of
take m_series Join in m_serieslist in m_serieslist.append(series);
Add to Qchart m_Chart->addSeries(m_serieslist[m_SeriesNum]);
Write data m_serieslist[lineNum]->append(x,y);
3、 Axis variables
QValueAxis *axisX; //x Axis
QValueAxis *axisY; //y Axis
These two are used to display the coordinate axis , And these two are yes Axis
qreal m_x;
qreal m_y;
It's actually used for punctuation
function
Just a few simple
1、 Click the legend to hide
void connectMarkers(); // Connect
void disconnectMarkers(); // disconnect
void handleMarkerClicked(); // Functions executed after connection
It is recommended to copy the function body directly , See the appendix at the end of the article
void Mychart::connectMarkers()
{
// Connect all markers to handler
const auto markers = m_Chart->legend()->markers();
for (QLegendMarker *marker : markers) {
// Disconnect possible existing connection to avoid multiple connections
QObject::disconnect(marker, &QLegendMarker::clicked,
this, &Mychart::handleMarkerClicked);
QObject::connect(marker, &QLegendMarker::clicked, this, &Mychart::handleMarkerClicked);
}
}
void Mychart::disconnectMarkers()
{
const auto markers = m_Chart->legend()->markers();
for (QLegendMarker *marker : markers) {
QObject::disconnect(marker, &QLegendMarker::clicked,
this, &Mychart::handleMarkerClicked);
}
}
void Mychart::handleMarkerClicked()
{
QLegendMarker* marker = qobject_cast<QLegendMarker*> (sender());
Q_ASSERT(marker);
switch (marker->type())
{
case QLegendMarker::LegendMarkerTypeXY:
{
// Toggle visibility of series
marker->series()->setVisible(!marker->series()->isVisible());
// Turn legend marker back to visible, since hiding series also hides the marker
// and we don't want it to happen now.
marker->setVisible(true);
// Dim the marker, if series is not visible
qreal alpha = 1.0;
if (!marker->series()->isVisible())
alpha = 0.5;
QColor color;
QBrush brush = marker->labelBrush();
color = brush.color();
color.setAlphaF(alpha);
brush.setColor(color);
marker->setLabelBrush(brush);
brush = marker->brush();
color = brush.color();
color.setAlphaF(alpha);
brush.setColor(color);
marker->setBrush(brush);
QPen pen = marker->pen();
color = pen.color();
color.setAlphaF(alpha);
pen.setColor(color);
marker->setPen(pen);
break;
}
default:
{
qDebug() << "Unknown marker type";
break;
}
}
}
2、 To be continued .....
It's done , But it's troublesome to transplant later , No longer use this method , change to the use of sth.
https://blog.csdn.net/qq_27620407/article/details/108734088 such
版权声明
本文为[Things will turn when they reach the extreme 1024]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210610057536.html
边栏推荐
- Calculation of fishing net road density
- Excel opens large CSV format data
- Ionic 从创建到打包指令集顺序
- 【ACM】455. Distribute Biscuits (1. Give priority to big biscuits to big appetite; 2. Traverse two arrays with only one for loop (use subscript index -- to traverse another array))
- NVIDIA Jetson: GStreamer and openmax (GST OMX) plug-ins
- Cygwin64 right click to add menu, and open cygwin64 here
- Connection mode of QT signal and slot connect() and the return value of emit
- Permission management with binary
- word frequency count
- 登录和发布文章功能测试
猜你喜欢

【ACM】455. Distribute Biscuits (1. Give priority to big biscuits to big appetite; 2. Traverse two arrays with only one for loop (use subscript index -- to traverse another array))

From introduction to mastery of MATLAB (2)

Custom prompt box MessageBox in QT

STM32学习记录0008——GPIO那些事1
Scikit learn sklearn 0.18 official document Chinese version

【ACM】509. 斐波那契数(dp五部曲)
![解决报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]](/img/5f/a80951777a0473fcaa685cd6a8e5dd.png)
解决报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

QT reading and writing XML files (including source code + comments)

Quantexa CDI(场景决策智能)Syneo平台介绍

Halo 开源项目学习(七):缓存机制
随机推荐
Daily CISSP certification common mistakes (April 13, 2022)
The difference between deep copy and shallow copy
PowerDesigner various font settings; Preview font setting; SQL font settings
【ACM】70. 爬楼梯
MySQL auto start settings start with systemctl start mysqld
Robocode tutorial 8 - advanced robot
Imx6 debugging LVDS screen technical notes
14个py小游戏源代码分享第二弹
Implement a simple function to calculate the sum of all integers between M ~ n (m < n)
From introduction to mastery of MATLAB (2)
Re expression régulière
Deep learning classic network analysis and target detection (I): r-cnn
Ionic 从创建到打包指令集顺序
The vivado project corresponding to the board is generated by TCL script
Introduction to quantexa CDI syneo platform
Using transmittablethreadlocal to realize parameter cross thread transmission
CISSP certified daily knowledge points (April 13, 2022)
C medium? This form of
QT add external font ttf
CISSP certified daily knowledge points (April 14, 2022)