QChartView *chartWidget= new QChartView();
chartView->setRenderHint(QPainter::Antialiasing);
chartView->resize(800, 300);
chartView->setRubberBand(QChartView::NoRubberBand);
chartView->setDragMode(QChartView::RubberBandDrag);
connect(chartWidget,&QChartView::rubberBandChanged,this,[=](QRect viewportRect, QPointF fromScenePoint, QPointF toScenePoint){
if (viewportRect.isNull()) {//结束选择
QScatterSeries *series = (QScatterSeries *)chartWidget->chart()->series().first();
QVector<QPointF> ver = series->pointsVector();
// qDebug() << "ver="<<ver;
for (const QPointF &p:ver) {
if (m_viewportRect.contains(chart_to_view_point(p))) {
qDebug() << "ver0 x="<<p.x()<<" y="<<p.y();
// emit signal_selected("scatter1",p);
}
}
// Debug() << "ver0 x="<<p.x()<<" y="<<p.y();
// for (int i = 0 ; i < series->points().size();i++){
// qDebug() << "-------------------------- " << i;
// }
}
else {
m_viewportRect = viewportRect;
}
});
QPoint MainWindow::chart_to_view_point(QPointF char_coord)
{
QPointF scene_point = chartWidget->chart()->mapToPosition(char_coord);
QPoint view_point = chartWidget->mapFromScene(scene_point);
return view_point;
}