title: Selecting QLineSeries in a QChartView using rubberband selection
body: <p>I have a QChart with a number of QLineSeries on it.</p>
  
  <p>I have created my own chart class <code>CPlotView</code> derifed from QChartView and overridden the mousePressEvent, mouseMoveEvent and mouseReleaseEvent as shown below.</p>
  
  <p>I want to implement both rubberband zoom and rubberband select separately, and I can choose which to do based on checkable QPushButtons (code not shown but its just a member of CPlotView which holds an enum value which defined what 'mode' its in (Zoom or Select)</p>
  
  <pre><code>void CPlotView::mousePressEvent(QMouseEvent *event)
  {
       if(PlotRubberBand)
       {
           if (PlotCursorMode == ECursorMode::eIsolate || PlotCursorMode == ECursorMode::eZoom)
           {
               QRectF plotArea = chart()-&gt;plotArea();
               if (PlotRubberBand-&gt;isEnabled()
                   &amp;&amp; event-&gt;button() == Qt::LeftButton
                   &amp;&amp; plotArea.contains(event-&gt;pos()))
               {
  
                   DrawRubberBand = true;
                   PlotRubberBandOrigin = event-&gt;pos();
                   PlotRubberBand-&gt;setVisible(true);
                   PlotRubberBand-&gt;setGeometry(QRect(PlotRubberBandOrigin, QSize()));
                   event-&gt;accept();
               }
               QGraphicsView::mousePressEvent(event);
  
           }
           else
           {
               QChartView::mousePressEvent(event);
           }
       }
  
      QChartView::mousePressEvent(event);
  }
  
  void CPlotView::mouseMoveEvent(QMouseEvent *event)
  {
      if (GetPlotCursorMode() == ECursorMode::eIsolate)
      {
          if (DrawRubberBand &amp;&amp; PlotRubberBand-&gt;isVisible())
          {
              QRect rect = chart()-&gt;plotArea().toRect();
              int width = event-&gt;pos().x() - PlotRubberBandOrigin.x();
              int height = event-&gt;pos().y() - PlotRubberBandOrigin.y();
  
              PlotRubberBand-&gt;setGeometry(QRect(PlotRubberBandOrigin.x(), PlotRubberBandOrigin.y(), width, height).normalized());
  
          }
          else
          {
               QGraphicsView::mouseMoveEvent(event);
          }
      }
      else if (GetPlotCursorMode() == ECursorMode::eZoom)
      {
          if (DrawRubberBand &amp;&amp; PlotRubberBand-&gt;isVisible())
          {
              QChartView::mouseMoveEvent(event);
          }
          else
          {
              QGraphicsView::mouseMoveEvent(event);
          }
      }
      else if (GetPlotCursorMode() == ECursorMode::eSelect)
      {
          QGraphicsView::mouseMoveEvent(event);
      }
      else
      {
          QChartView::mouseMoveEvent(event);
  
      }
  
  }
  
  void CPlotView::mouseReleaseEvent(QMouseEvent *event)
  {
      if (PlotRubberBand-&gt;isVisible())
      {
          if (PlotCursorMode == ECursorMode::eIsolate)
          {
               DrawRubberBand = false;
               PlotRubberBand-&gt;setVisible(false);
  
              QGraphicsView::mouseReleaseEvent(event);
  
              QList&lt;QGraphicsItem *&gt; selected_items = QGraphicsView::items(PlotRubberBand-&gt;rect(), Qt::IntersectsItemShape);
  
              qDebug() &lt;&lt; "found " &lt;&lt; selected_items.size() &lt;&lt; " items"; // this appears to show a number of items, but how do I detect which items are my data series, if any are?
              for (auto&amp; item : selected_items)
              {
                  // detect which are my data series and highlight them as selected
              }
  
          }
          else
          {
              DrawRubberBand = false;
              PlotRubberBand-&gt;setVisible(false);
              QChartView::mouseReleaseEvent(event);
          }
      }
  }
  </code></pre>
  
  <p>I have now got the zoom mode working - clicking the 'zoom' mode button then dragging the rubberband on the plot zooms into that area. Clicking the select mode button draws the rubberband but doesn't zoom. I want to now select all data series in the rubberband in select mode.</p>
  
  <p>In <code>mouseReleaseEvent</code> in select mode, I am attempting to capture all selected <code>QGraphicsItems</code> inside the rubberband rect (I'm hoping that is what is returned by <code>QGraphicsView::items(PlotRubberBand-&gt;rect(), Qt::IntersectsItemShape);</code>), but I don't know how to detect my data series (I actually have a mixture of QLineSeries and QScatterSeries.</p>
  
  <p>There are some <code>QGraphicsItems</code> being returned by <code>QGraphicsView::items(PlotRubberBand-&gt;rect(), Qt::IntersectsItemShape);</code> even when I don't intersect the rubberband with any of my data so it is obviously returning some other items in the scene.</p>
  
  <p>I tried doing a <code>dynamic_cast</code> of what is returned by <code>QGraphicsView::items</code> to a <code>QLineSeries</code>, but that didn't work. I can't help but think I'm making this more complicated than it should be.</p>
  
  <p><strong>UPDATE1:</strong> I have also tried capturing the signals fired when the mouse hovers over the data series during the rubberband select using:</p>
  
  <pre><code>connect(line_series, SIGNAL(hovered(const QPointF &amp;, bool)), this, SLOT(OnDataHovered(const QPointF&amp;, bool)));
  </code></pre>
  
  <p>but the signal doesn't fire when rubberband dragging (perhaps when left mouse button is down it doesn't fire?). :(</p>
  
  <p><strong>UPDATE 2:</strong> I have tried setting the selectionArea in the mouseReleaseEvent() call, and again, some this are returned as selected, far fewer than calling <code>QGraphicsView::items()</code>, but not my series as far as I can tell:</p>
  
  <pre><code>void ewbearinghistorychart::CEwBearingHistoryChartView::mouseReleaseEvent(QMouseEvent *event)
  {
      if (PlotRubberBand-&gt;isVisible())
      {
          if (PlotCursorMode == ECursorMode::eIsolate)
          {
              DrawRubberBand = false;
              PlotRubberBand-&gt;setVisible(false);
              QRect rubberband_rect = PlotRubberBand-&gt;rect();
              QGraphicsView::mouseReleaseEvent(event);
  
              // ************** new code **************
              QPolygonF p = chart()-&gt;mapToScene(PlotRubberBand-&gt;rect().normalized());
              QPainterPath path;
              path.addPolygon(p);
              chart()-&gt;scene()-&gt;setSelectionArea(path, Qt::IntersectsItemShape);
              QList&lt;QGraphicsItem *&gt; selected_items = chart()-&gt;scene()-&gt;selectedItems();
              qDebug() &lt;&lt; "selected items: " &lt;&lt; selected_items.size();
              // ************** /new code **************                
          }
          else
          {
              DrawRubberBand = false;
              PlotRubberBand-&gt;setVisible(false);
              QChartView::mouseReleaseEvent(event);
          }
      }
  }
  </code></pre>