QCustomPlot Discussion and Comments

Adding checkbox next to legenditems do enable/disable graphReturn to overview

Hello everyone,

I am using for a option to add checkboxes in my legend next to every legend item, which are checked by default. When I uncheck a box, I want my graph to set to invisible. Here is my Plot now: https://ibb.co/ynQm4Cg.

I added my legend like this:

    QCPLayoutGrid *subLayout = new QCPLayoutGrid;
    ui->plot_gyroscope->plotLayout()->addElement(0, 1, subLayout);
    subLayout->addElement(0, 0, new QCPLayoutElement);
    subLayout->addElement(1, 0, ui->plot_gyroscope->legend);
    subLayout->addElement(2, 0, new QCPLayoutElement);
    ui->plot_gyroscope->plotLayout()->setColumnStretchFactor(1, 0.001);

In an other thread (https://www.qcustomplot.com/index.php/support/forum/1102), somone wrote:
"wo options come to mind:
Either you subclass the QCPPlottableLegendItem and add the checkable functionality (which can then directly set its plottable's visibility), or you create a brand new QCPLayoutElement which only represents a checkbox and place that in the legend next to the plottable legend items"

I would like to use the second option, but I don't know how to implement this (I am a C++, Qt and QCustomPlot Newbie ;)). So can someone give me a hint, how to do that? Especially I cannot control how I can put this checkBoxelement right next to each of my legend items.


I have a simple solution for you - for manage the visibility of graph you can add and place checkboxes under the chart, and then checked a state of checkboxes.
After that the form will look like this:https://ibb.co/T4QqcVM
Here is my code:

void MyForm::on_checkBox_1_stateChanged(int arg1)
    if (arg1)
    else wGraphic->graph(0)->setVisible(false);

Where wGraphic is QCustomPlot();

Thank you Ivan,

this came into my mind too, but this would take unnecessary widget space, therefore I thought it would be a better solution, if the checkboxes are next to the legend item, because thus I do not need do add test next to them which saves space..