Hi

I have a widget container in my mainwindow.ui and two push buttons. Buttons are responsible to display chart on a widget (exactly piechart). One button has some data, the second one has different. In a nutshell, one button one chart.
The point is that I want to display charts in one widget container according which button has been clicked. If i push button1 it should display piechart number 1 on the widget. If i push button2 it should display piechart2 (in widget cointainer)
And it should be possible to push buttons multiple times and every time the proper chart should be displayed.

It looks like this. Now the button1 is clicked, so it display chart WYDATKI. And when I push button2 it should display another chart, in the same place.

widget.PNG

my code for button1 (for button2 is the same, but with different data)

Qt Code:
  1. void MainWindow::on_PieChart_pushButton_Przychody_clicked()
  2. {
  3.  
  4. QChart *chart = kategoriePieChart::makePieChart("przychody"); // function makePieChart return chart with data
  5. QChartView *chartView = new QChartView(chart);
  6.  
  7. QVBoxLayout *mainLayout = new QVBoxLayout;
  8. mainLayout->addWidget(chartView);
  9.  
  10. ui->widget_piechart->setLayout(mainLayout);
  11. }
To copy to clipboard, switch view to plain text mode 

I tried using widget->hide() and widget->show() but it's probably not the valid solution