The codes are:
QVectot<double> pos;

QCPItemLine *line = new QCPItemLine(MyPlot);
line->setSelectable(true);
line->setClipToAxisRect(false);
// set axis and position of line->start
line->start->setType(QCPItemPosition::ptPlotCoords);
line->start->setAxes(Rect_0->axis(QCPAxis::atLeft),Rect_0->axis(QCPAxis::atBottom));
line->start->setCoords(pos,Rect_0->axis(QCPAxis::atBottom)->range().lower);

// set axis and position of line->end
line->end->setType(QCPItemPosition::ptPlotCoords);
line->end->setAxes(rRect_n->axis(QCPAxis::atLeft),Rect_n->axis(QCPAxis::atBottom));
line->end->setCoords(pos,Rect_n->axis(QCPAxis::atBottom)->range().upper);

Rect_i is element in same QCPLayoutGrid *MyGrid. "i" in Rect_i is colum index in MyGrid, 0<=i<=n.

the issues are:
1) how can drag line vertical at the same time, line->start move with line->end vertically.
2) only limit to drag line, user can't drag other QCPGraphs in Rect_i.
3) how to realize user dragging line in any Rect_i.

thanks in advance.