QCustomPlot Discussion and Comments

How to prevent deselecting plottables from selecting axisReturn to overview

I have a group of axis and a group of graphs. I want that when an axis is selected, selected graphs won't be affected.
Similarly, when a graph is selected, the selected axis won't be deselected.

Is there any easy way to achieve this?

For custom selection behavior you'll probably want to make a QCustomPlot subclass and reimplement the method
processPointSelection

For reference, its current implementation looks like this:

void QCustomPlot::processPointSelection(QMouseEvent *event)
{
  QVariant details;
  QCPLayerable *clickedLayerable = layerableAt(event->pos(), true, &details);
  bool selectionStateChanged = false;
  bool additive = mInteractions.testFlag(QCP::iMultiSelect) && event->modifiers().testFlag(mMultiSelectModifier);
  // deselect all other layerables if not additive selection:
  if (!additive)
  {
    foreach (QCPLayer *layer, mLayers)
    {
      foreach (QCPLayerable *layerable, layer->children())
      {
        if (layerable != clickedLayerable && mInteractions.testFlag(layerable->selectionCategory()))
        {
          bool selChanged = false;
          layerable->deselectEvent(&selChanged);
          selectionStateChanged |= selChanged;
        }
      }
    }
  }
  if (clickedLayerable && mInteractions.testFlag(clickedLayerable->selectionCategory()))
  {
    // a layerable was actually clicked, call its selectEvent:
    bool selChanged = false;
    clickedLayerable->selectEvent(event, additive, details, &selChanged);
    selectionStateChanged |= selChanged;
  }
  if (selectionStateChanged)
  {
    emit selectionChangedByUser();
    replot(rpQueuedReplot);
  }
}

If I understand you right, then you'll probably want to slightly change that first deselection loop to only act on layerables which have the same QCPAxis or QCPAbstractPlottable base class as the clickedLayerable.

If you're also using rect selection, you can do the same with processRectSelection.

Hi DerManu,

Actually, subclass QCustomPlot can't access selectionCategory, selectEvent, deselectEvent.

so I think it is easy way is like this: set QCP::iMultiSelect flag and set Qt::NoModifier flag.