PDA

View Full Version : Displaying new widget on the another one



time
22nd November 2016, 14:44
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.

12229

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



void MainWindow::on_PieChart_pushButton_Przychody_click ed()
{

QChart *chart = kategoriePieChart::makePieChart("przychody"); // function makePieChart return chart with data
QChartView *chartView = new QChartView(chart);

QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(chartView);

ui->widget_piechart->setLayout(mainLayout);
}


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

rawfool
22nd November 2016, 15:06
You may use QStackedLayout, add widgets and use void setCurrentIndex(int index) on button click to show the appropriate widget.

anda_skoa
22nd November 2016, 20:49
I would recommend to use QStackedWidget instead of QStackedLayout.

Cheers,
_