PDA

View Full Version : Common buttons on a stacked widget



premroxx
20th September 2011, 03:50
I have a Gui that has few layers/steps. Currently i'm using a stacked widget. When u press next it goes to the next widget. When u press back it goes back to the previous one. Can i make the 'next' & 'back' button common to all widgets ie. i dont want to make a separate 'next' & 'back' button for every single widget

This is the code.
v
oid MainWindow::on_pb_back_clicked()
{
curr = this->ui->stackedWidget->currentIndex();
this->ui->stackedWidget->setCurrentIndex(curr-1);
}

void MainWindow::on_pb_next_clicked()
{
curr = this->ui->stackedWidget->currentIndex();
this->ui->stackedWidget->setCurrentIndex(curr+1);
}

ChrisW67
20th September 2011, 04:24
Don't put those widgets on the QStackedWidget.

BTW: Have you looked at QWizard?

premroxx
20th September 2011, 19:12
I tried to avoid stackedwidget, by stacking the labels/comboboxes on top of each other & showing/hiding them based on the 'begin/next'. But that slowed down the gui. So i started using stacked widgets. Qwizard mainly seems to used particularly for setup. I will try it if this doesnt work

ChrisW67
20th September 2011, 19:59
You have missed the point: put the Next and Previous buttons in the same container as the QStackedWidget. The QStackedWidget contains the pages of other widgets. Have a look at the attached Designer file

tomorrow
15th November 2013, 23:02
sorry to bring up the old thread, but when you are adding this


void get_started::on_pushButton_clicked()
{
curr = this->ui->stackedWidget->currentIndex();
this->ui->stackedWidget->setCurrentIndex(curr+1);
}

void get_started::on_pushButton_2_clicked()
{
curr = this->ui->stackedWidget->currentIndex();
this->ui->stackedWidget->setCurrentIndex(curr-1);
}


*ps : I managed to get it working , sorry for this post