scene.clear(); QPen dashPen; dashPen.setStyle(Qt::DashLine); for (int i = 0; i < Points.size() - 1; i++) { QPointF p1, p2; QLineF polyLine; p1 = Points[i]; p2 = Points[i+1]; polyLine = QLineF(p1, p2); polyLine->setPen(dashPen); scene.addLine(polyLine); polyLine = QLineF(); p1 = QPointF(); p2 = QPointF(); }
i < Points.size() - 1
for (int i = 0; i < Points.size() - 1; i++) scene.addLine(QPointF(Points[i], Points[i+1]), QPen(Qt::DashLine));
voidMainWindow::autoscale(){ if (!Points.size()) return; double xmin = Points[0].x(), ymin = Points[0].y(); double xmax = xmin, ymax = ymin; for (unsigned i = 1; i < Points.size(); ++i) { if (Points[i].x() < xmin) xmin = Points[i].x(); if (Points[i].x() > xmax) xmax = Points[i].x(); if (Points[i].y() < ymin) ymin = Points[i].y(); if (Points[i].y() > ymax) ymax = Points[i].y(); } QRectF rect(QPointF(xmin, ymin), QPointF(xmax, ymax)); double mx = rect.width() * 0.05; double my = rect.height() * 0.05; rect.adjust(-mx, -my, mx, my); scene.setSceneRect(rect); ui.graphicsView->fitInView(rect, Qt::KeepAspectRatio); ui.graphicsView->centerOn(rect.center());}