How do you plot points in QT?

前端 未结 4 2181
渐次进展
渐次进展 2021-02-04 20:00

I am writing an application in C++ with QT where you have n points and compute the convex hull of this. However, once this is computed I have no idea how to plot the points and

4条回答
  •  旧时难觅i
    2021-02-04 20:23

    Qt Charts, QML or GraphicsView

    This was going to be an update to my QGraphics View example, but it got kind of long, and it really is a completely different method to answer the question.

    Qt Charts (LGPL available since 2016) is a great way to do this without needing a third party library.

    • https://doc.qt.io/qt-5/qtcharts-linechart-example.html
    • http://blog.qt.io/blog/2016/01/18/qt-charts-2-1-0-release/
    • https://doc.qt.io/qt-5/qtcharts-overview.html

    https://doc.qt.io/qt-5/qlineseries.html#QLineSeries

    QLineSeries* series = new QLineSeries();
    series->append(0, 6);
    series->append(2, 4);
    ...
    chart->addSeries(series);
    

    For the convex hull example specifically, you probably want the QAreaSeries chart.

    https://doc.qt.io/qt-5/qtcharts-areachart-example.html
    https://doc.qt.io/qt-5/qareaseries.html

    QLineSeries *series0 = new QLineSeries();
    QLineSeries *series1 = new QLineSeries();
    *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12, 6)
             << QPointF(16, 7) << QPointF(18, 5);
    *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12, 3)
             << QPointF(16, 4) << QPointF(18, 3);
    QAreaSeries *series = new QAreaSeries(series0, series1);
    

    Hope that helps.

提交回复
热议问题