C
C
Clean Coder2019-04-15 14:57:35
Qt
Clean Coder, 2019-04-15 14:57:35

How to implement adding point to QGraphicsView?

Hello. Started learning Qt. There was such a question. Wrote a simple program that displays a lot of points on QGraphicsView. While I add all the points in the code itself through initialization.

void Graphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    std::vector<QPointF> points = {{10, 20}, {-30, 30}, {-40, 20}, {-50, 0}, {-60, 20}, {-75, 25},
                                   {-20, 10}, {-30, 15}, {25, 40}, {35, 35}, {50, 40}, {60, 70}};

    QPen pen(Qt::red, 4);
    painter->setPen(pen);
    for(auto& it = points.begin(); it != points.end(); ++it){
        painter->drawPoint(*it);
    }
    Q_UNUSED(option);
    Q_UNUSED(widget);
}

I want to make it possible to add points in the program itself. That is, let's say I enter coordinates through SpinBoxes, I press the button, and the point appears on the chart. How to make it easier?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question