当前位置:网站首页>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
边栏推荐
- Const keyword, variable and function are decorated with const
- Realization of consumer gray scale
- Rust: how to implement a thread pool?
- Selenium + phantom JS crack sliding verification 2
- Test questions of daily safety network (February 2024)
- 函数递归以及趣味问题的解决
- Flash operates on multiple databases
- Quantexa CDI(场景决策智能)Syneo平台介绍
- Selenium + webdriver + chrome realize Baidu to search for pictures
- Box pointer of rust
猜你喜欢
Re regular expression
Qt读写XML文件(含源码+注释)
Dynamically add default fusing rules to feign client based on sentinel + Nacos
7-21 wrong questions involve knowledge points.
Win1远程出现“这可能是由于credssp加密oracle修正”解决办法
Resolve the error Max virtual memory areas VM max_ map_ count [65530] is too low, increase to at least [262144]
How to restore MySQL database after win10 system is reinstalled (mysql-8.0.26-winx64. Zip)
Gobang game based on pyGame Library
QT tablewidget insert qcombobox drop-down box
解决允许在postman中写入注释请求接口方法
随机推荐
14 py games source code share the second bullet
According to the result set queried by SQL statement, it is encapsulated as JSON
ArcGIS table to excel exceeds the upper limit, conversion failed
Rust: shared variable in thread pool
Halo 开源项目学习(七):缓存机制
Map basemap Library
【ACM】509. 斐波那契数(dp五部曲)
Introduction to quantexa CDI syneo platform
Robocode Tutorial 4 - robocode's game physics
Calculation of fishing net road density
Matlab tips (6) comparison of seven filtering methods
Quantexa CDI(场景决策智能)Syneo平台介绍
【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))
Spark performance optimization guide
Robocode tutorial 7 - Radar locking
Quantexa CDI(场景决策智能)Syneo平台介绍
JD-FreeFuck 京東薅羊毛控制面板 後臺命令執行漏洞
Creation and use of QT dynamic link library
【ACM】376. Swing sequence
QT notes on qmap container freeing memory