Qt QGraphicsScene add and delete lines
<p>I am (very) new to Qt and I am trying to make a simple plot (without involving external libraries&amp;co), which also has a box, axes, and grid lines, which I want to be able to toggle.</p>

<p>I have the <code>QGraphicsScene</code> defined as <code>scene</code> where I can use <code>scene-&gt;addLine(...)</code>, but I don't know how I can remove those lines based on a <code>QCheckBox</code>. This is (in short) what I have set in the function <code>plotAxes()</code> which will be used with <code>connect()</code>:</p>

<pre><code>    QGraphicsLineItem *xAxis {new QGraphicsScene::addLine(xMin, 0, xMax, 0, *dashedLine)};
    if (boxToggle-&gt;isChecked())
    {
        scene-&gt;addItem(xAxis);
        //scene-&gt;addLine(yCenter, yMin, yCenter, yMax, *dashedLine);
        scene-&gt;update();
    }
    else
    {
        scene-&gt;removeItem(xAxis);
        scene-&gt;update();
    }
</code></pre>

<p>The code only shows the first axis, if it works for that I can extend to everything else, but it doesn't work. For <code>xAxis</code> I tried <code>QGraphicsItem</code>, <code>QGraphicsScene</code>, combinations, but this isn't how I want to continue. I don't know how to add the line (axis) as a variable, or pointer, and then use that to add/delete to/from the scene. Can someone please tell me how to do it?</p>

<hr>

<p>[edit]
I'm sorry, forgot to say I want to be able to toggle them without affecting what's already plotted.</p>