toggle QLineSeries visibility with QPushButton & connect?
Solved
General and Desktop
-
Hi
I just wonder how I can accomplish a toggle visibility of a bunch of QLineSeries with some QPushButton's. I have 2 QLineSeries and 2 QPushButtons. Then I wrote 2 public slot functions for each series/button and connected them to each other.Is there a more elegant way like having only one toggle function that gets passed the series name as parameter? But how to connect then signal and slot?
I have now:
tabwidget.cpp:
TabWidget::TabWidget(QTabWidget *parent) : QTabWidget(parent) {... seriesPressure = new QtCharts::QLineSeries(); seriesTempIn = new QtCharts::QLineSeries(); ... pbTempIn = new QPushButton("Pressure",tab3); pbTempIn->setCheckable(1); pbTempIn->setChecked(1); pbTempOut = new QPushButton("Temp In",tab3); pbTempOut->setCheckable(1); pbTempOut->setChecked(1); connect(pbTempIn,&QPushButton::clicked,this,&TabWidget::toggleSeriesTempIn); connect(pbTempOut,&QPushButton::clicked,this,&TabWidget::toggleSeriesTempOut); ...} void TabWidget::toggleSeriesTempIn() { if(pbTempIn->isChecked()) { seriesTempIn->show(); } else seriesTempIn->hide(); } void TabWidget::toggleSeriesTempOut() { if(pbTempIn->isChecked()) { seriesTempIn->show(); } else seriesTempIn->hide(); }