Reputation: 363
My application have an "actionhelp" in the menu bar which when clicked opens up a QDialog that contains an ok button at the other side in the mainwindow i have a QStackedWidget So my question is how to change the index of the stackedwidget when i press that ok button in the QDialog??
Upvotes: 1
Views: 546
Reputation: 157
Signals and slots. Connect the signal from the ok button (or emit one of your own when checking QDialog::Accepted after it closes) to a slot that will change the index in the QStackedWidget.
Example code:
Create and connect QAction in main method:
QAction *displayDialog = new QAction("Display Dialog", this);
connect(popup, SIGNAL(triggered()), this, SLOT(showDialog()));
Display Dialog:
void showDialog()
{
YourDialog *dialog = new YourDialog(this);
int return_code = dialog.exec();
if (return_code == QDialog::Accepted)
{
int index = someValue;
qStackedWidget.setCurrentIndex(index);
}
}
Upvotes: 2
Reputation: 7891
Assuming you have a line edit on your dialog and you want to change the index of stacked widget based on the line edit value ( or a spin box ):
//your dialog
//the constructor
YourDialog::YourDialog(QWidget*parent)
:QDialog(parent)
{
connect(ur_ok_btn, SIGNAL(clicked()), SLOT(accept ()));
}
//access to line edit value
QString YourDialog::getUserEnteredValue(){return ur_line_edit->text();}
Where you create an instance of YourDialog class :
//your main window
YourDialog dlg;
if( dlg.exec() == QDialog::Accepted ){
int i = dlg.getUserEnteredValue().toInt();
ur_stacked_widget->setCurrentIndex(i);
}
Upvotes: 0