0

Now I need to draw some polylines according to their coordinates. These are coordinates of one poltline:

 1.15109497070313E+02 2.73440704345703E+01
 1.15115196228027E+02 2.73563938140869E+01
 1.15112876892090E+02 2.73697128295898E+01
 1.15108222961426E+02 2.73687496185303E+01
 1.15081001281738E+02 2.73908023834229E+01
 1.15078292846680E+02 2.73949108123779E+01
 1.15073806762695E+02 2.74090080261230E+01
 1.15063293457031E+02 2.74221019744873E+01
 1.15059646606445E+02 2.74324569702148E+01

I've drawn these polylines and moved them to the center of window:

QPainter painter(this);
QPainterPath path;
for (auto& arc : layer.getArcs()) {
    for (int i = 0; i < arc.pts_draw.size() - 1; i++)
    {
        QPolygonF polygon = QPolygonF(arc.pts_draw);
        path.addPolygon(polygon);
    }
}

// move all polylines to the center of window
QPointF offset = rect().center() - path.boundingRect().center();
painter.translate(offset);

painter.drawPath(path);

However, what I got in the window was this:
enter image description here
I think it's caused by the coordinates. All coordinates are very close to each other so the graphics will become too small when drawn in the window. So my problem is how to scale the graphics properly? In other words, how can I know the ratio of scaling?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
maxwellhertz
  • 473
  • 1
  • 6
  • 18

1 Answers1

0

On the QGraphicsView you can call scale(qreal sx, qreal sy) to scale the QGraphicsScene and all it's QGraphicsItems. If you wish to scale each item individually instead of the entire scene, then take each point in the polygon and use Euclidian geometry scaling to scale your polygon. Or you could use something called QTransform like this post did