Home > Back-end >  O great god answer!!!!! About QCustomplot multiple axes QCPItemTracer cursor issue!
O great god answer!!!!! About QCustomplot multiple axes QCPItemTracer cursor issue!

Time:01-30

Recently doing a simulation waveform of the module, with the help of QCustomplot, one function is to imitate the matlab subplot, my train of thought is to create multiple axes QCPAxisRect, then added to coordinate Graph, with QCPItemTracer finally with Graph binding, layout aspects with plotLayout () - & gt; AddElement () to add the line, I now is the problem of whether the cursor tracer which Graph binding, and he only displayed on line "0 0 column axis, the other axis does not show that I don't know whether this new QCPAxisRect this rectangle realize this display vernier, I also don't know whether my thinking is wrong, please everyone a great god can answer!!!!! Below is the code of the test with renderings,

 
MainWindow: : MainWindow (QWidget * parent)
: QMainWindow (parent)
, the UI (new UI: : MainWindow)
{
The UI - & gt; SetupUi (this);
test();
For (int I=0; I & lt; 3; I++) {
Tracer [I]=new QCPItemTracer (UI - & gt; CustomPlot);
Tracer [I] - & gt; SetPen (QPen (Qt: : DashLine));
Tracer [I] - & gt; SetStyle (QCPItemTracer: : tsPlus);//the cursor style: cross, circle, square, etc.

TracerLabel [I]=new QCPItemText (UI - & gt; CustomPlot);//generate cursor description
//the following code is set cursor appearance and alignment of this state
TracerLabel [I] - & gt; SetLayer (" overlay ");
TracerLabel [I] - & gt; The position - & gt; SetCoords (0.5 0);
TracerLabel [I] - & gt; The setFont (QFont (the font (). Family (), 10));
TracerLabel [I] - & gt; SetPen (QPen (Qt: : black));
TracerLabel [I] - & gt; SetPositionAlignment (Qt: : AlignLeft | Qt: : AlignTop);
TracerLabel [I] - & gt; SetBrush (Qt: : green);
//the following statement is very important, it will be a cursor that anchoring in the tracer location, automatically follow
TracerLabel [I] - & gt; The position - & gt; SetParentAnchor (tracer [I] - & gt; The position);

M_lineV [I]=new QCPItemStraightLine (UI - & gt; CustomPlot);
QPen linesPen (Qt: : red, 1, Qt: : SolidLine);
M_lineV [I] - & gt; SetLayer (" overlay ");
M_lineV [I] - & gt; SetPen (linesPen);
M_lineV [I] - & gt; SetClipToAxisRect (true);
M_lineV [I] - & gt; Point1 - & gt; SetCoords (0, 0);
M_lineV [I] - & gt; Point2 - & gt; SetCoords (0, 0);
}
The connect (UI - & gt; CustomPlot, & amp; QCustomPlot: : mouseMove, this, & amp; MainWindow: : myMoveEvent);
}

MainWindow: : ~ MainWindow ()
{
Delete the UI;
}

Void MainWindow: : myMoveEvent (QMouseEvent * event)
{
Double xValue;
Double yValue;

QDebug () & lt; <"Aaaa";
Double yy=wideAxisRect - & gt; The axis (QCPAxis: : atBottom) - & gt; PixelToCoord (event - & gt; Pos (.) (x));
M_lineV [0] - & gt; Point1 - & gt; SetCoords (yy, 1);
M_lineV [0] - & gt; Point2 - & gt; SetCoords (yy, 0);
Tracer [0] - & gt; SetGraph (mainGraphCos);//the cursor and the curve of the layer to connect
Tracer [0] - & gt; The position - & gt; SetAxes (wideAxisRect - & gt; The axis (QCPAxis: : atBottom), wideAxisRect - & gt; The axis (QCPAxis: : atLeft));
Tracer [0] - & gt; SetGraphKey (yy);//the cursor x-coordinate abscissa (key) set up the fresh-from-stats-class obtain data
Tracer [0] - & gt; SetInterpolating (true);//the cursor ordinate can be obtained automatically by the linear interpolation curve data (which need not to calculate manually)
Tracer [0] - & gt; UpdatePosition ();//that just sets the cursor position of longitude and effective
//the following code is used to update the cursor shows that the content of the
XValue=https://bbs.csdn.net/topics/tracer [0] -> position -> key ();
YValue=https://bbs.csdn.net/topics/tracer [0] -> position -> value ();
The contents of the//set the cursor (tracerLabel)
TracerLabel [0] - & gt; SetText (QString (x=% 1, y="% 2"). Arg (xValue). Arg (yValue));

Double xx=subRectLeft - & gt; The axis (QCPAxis: : atBottom) - & gt; PixelToCoord (event - & gt; Pos (.) (x));
M_lineV [1] - & gt; Point1 - & gt; SetCoords (xx, 1);
M_lineV [1] - & gt; Point2 - & gt; SetCoords (xx, 0);
Tracer [1] - & gt; SetGraph (subGraphRandom);//the cursor and the curve of the layer to connect
Tracer [1] - & gt; The position - & gt; SetAxes (subRectLeft - & gt; The axis (QCPAxis: : atBottom), subRectLeft - & gt; The axis (QCPAxis: : atLeft));
Tracer [1] - & gt; SetGraphKey (xx);//the cursor x-coordinate abscissa (key) set up the fresh-from-stats-class obtain data x
Tracer [1] - & gt; SetInterpolating (true);//the cursor ordinate can be obtained automatically by the linear interpolation curve data (which need not to calculate manually)
Tracer [1] - & gt; UpdatePosition ();//that just sets the cursor position of longitude and effective
//the following code is used to update the cursor shows that the content of the
XValue=https://bbs.csdn.net/topics/tracer [1] -> position -> key ();
YValue=https://bbs.csdn.net/topics/tracer [1] -> position -> value ();
The contents of the//set the cursor (tracerLabel)
TracerLabel [1] - & gt; SetText (QString (x=% 1, y="% 2"). Arg (xValue). Arg (yValue));


Double x=subRectRight - & gt; The axis (QCPAxis: : atBottom) - & gt; PixelToCoord (event - & gt; Pos (.) (x));
M_lineV [2] - & gt; Point1 - & gt; SetCoords (x, 1);
M_lineV [2] - & gt; Point2 - & gt; SetCoords (x, 0);
Tracer [2] - & gt; SetGraph (subBars);//the cursor and the curve of the layer to connect
Tracer [2] - & gt; The position - & gt; SetAxes (subRectRight - & gt; The axis (QCPAxis: : atBottom), subRectRight - & gt; The axis (QCPAxis: : atLeft));
Tracer [2] - & gt; SetGraphKey (x);//the cursor x-coordinate abscissa (key) set up the fresh-from-stats-class obtain data x
Tracer [2] - & gt; SetInterpolating (true);//the cursor ordinate can be obtained automatically by the linear interpolation curve data (which need not to calculate manually)
Tracer [2] - & gt; UpdatePosition ();//that just sets the cursor position of longitude and effective
//the following code is used to update the cursor shows that the content of the
XValue=https://bbs.csdn.net/topics/tracer [2] -> position -> key ();
YValue=https://bbs.csdn.net/topics/tracer [2] -> position -> value ();
The contents of the//set the cursor (tracerLabel)
TracerLabel [2] - & gt; SetText (QString (x=% 1, y="% 2"). Arg (xValue). Arg (yValue));

The UI - & gt; CustomPlot - & gt; Replot ();
}

Void MainWindow: : test ()
{
The UI - & gt; CustomPlot - & gt; PlotLayout () - & gt; clear();//first of all to empty the default axis rectangular, let's start from scratch

The UI - & gt; CustomPlot - & gt; SetInteractions (QCP: : iRangeDrag | QCP: : iRangeZoom | QCP: : iSelectPlottables | QCP: : iSelectLegend);
WideAxisRect=new QCPAxisRect (UI - & gt; CustomPlot);//remember setupDefaultAxes to true, the role of, forget to turn up to see if the
WideAxisRect - & gt; SetupFullAxesBox (true);//let the four axis, and display all
WideAxisRect - & gt; AddAxis (QCPAxis: : atLeft) - & gt; SetTickLabelColor (QColor (# 6050 "f8")); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related