当前位置:网站首页>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
边栏推荐
- Ionic 从创建到打包指令集顺序
- RC smart pointer in rust
- powerdesigner各种字体设置;preview字体设置;sql字体设置
- mysql自动启动设置用Systemctl start mysqld启动
- 14个py小游戏源代码分享第二弹
- 【ACM】376. 摆动序列
- Resolve the error Max virtual memory areas VM max_ map_ count [65530] is too low, increase to at least [262144]
- Analysez l'objet promise avec le noyau dur (Connaissez - vous les sept API communes obligatoires et les sept questions clés?)
- Use of regular expressions in QT
- Robocode tutorial 7 - Radar locking
猜你喜欢
Nodejs installation
Qt读写XML文件(含源码+注释)
Cygwin64 right click to add menu, and open cygwin64 here
解决允许在postman中写入注释请求接口方法
Stm32mp157 wm8960 audio driver debugging notes
Deep learning classic network analysis and target detection (I): r-cnn
【ACM】509. 斐波那契数(dp五部曲)
In win10 system, all programs run as administrator by default
Differences between SSD hard disk SATA interface and m.2 interface (detailed summary)
How to install jsonpath package
随机推荐
【ACM】376. 摆动序列
Docker 安裝 Redis
Crawler for querying nicknames and avatars based on qqwebapi
logstash 7. There is a time problem in X. the difference between @ timestamp and local time is 8 hours
硬核解析Promise對象(這七個必會的常用API和七個關鍵問題你都了解嗎?)
Function recursion and solving interesting problems
Imx6 debugging LVDS screen technical notes
Jenkspy package installation
解决报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
Flash operates on multiple databases
The difference between deep copy and shallow copy
Mode of interprocess communication
JD freefuck Jingdong HaoMao control panel background Command Execution Vulnerability
Daily CISSP certification common mistakes (April 11, 2022)
消费者灰度实现思路
Error reported when running tensorboard: valueerror: duplicate plugins for name projector, solution
In win10 system, all programs run as administrator by default
Refcell in rust
Robocode tutorial 8 - advanced robot
Nodejs installation