How to draw inside qtcharview?

Viewed 71

I have managed to draw some lines on top of the qchartview, if the window isn't resized it is acceptable. However when i resize the line does not scale as shown below.

enter image description here

How can i draw a vertical line so its bound by the current windows rectangle and adjusts when the window is resized?

void ChartView::mousePressEvent(QMouseEvent *event)
    {
        if (m_isTouching)
            return;

        if( event->modifiers() & Qt::ShiftModifier )
        {

            qreal xVal = chart()->mapToValue(event->pos()).x();
            qreal yVal = chart()->mapToValue(event->pos()).y();


            QGraphicsLineItem* linex = this->scene()->addLine(0+xVal,50,0+xVal,500);
                line.push_back(linex);
                line.back()->setFlag(QGraphicsItem::ItemIsMovable);
        }

        if( event->modifiers() & Qt::ControlModifier)
        {
            for(auto& item : line)
            {
                if(this->scene() != NULL )
                {
                    this->scene()->removeItem(item);
                }
            }
        }

        QChartView::mousePressEvent(event);

    }
0 Answers
Related