我的应用程序在菜单栏中有一个“actionhelp”,单击它会打开一个 QDialog,其中在主窗口的另一侧包含一个 ok 按钮我有一个 QStackedWidget 所以我的问题是当我按下它时如何更改stackedwidget 的索引QDialog中的确定按钮??
2 回答
            2        
        
		
信号和插槽。将来自确定按钮的信号(或在关闭后检查 QDialog::Accepted 时发出您自己的信号)连接到将更改 QStackedWidget 中的索引的插槽。
示例代码:
在 main 方法中创建并连接 QAction:
QAction *displayDialog = new QAction("Display Dialog", this);
connect(popup, SIGNAL(triggered()), this, SLOT(showDialog()));
显示对话框:
void showDialog()
{
    YourDialog *dialog = new YourDialog(this);
    int return_code = dialog.exec();
    if (return_code == QDialog::Accepted)
    {
        int index = someValue;
        qStackedWidget.setCurrentIndex(index);
    }
}
    于 2013-03-19T10:30:00.783   回答
    
    
            0        
        
		
假设您在对话框中有行编辑,并且您想根据行编辑值(或旋转框)更改堆叠小部件的索引:
//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();}
在哪里创建 YourDialog 类的实例:
 //your main window
    YourDialog dlg;
    if( dlg.exec() == QDialog::Accepted ){
        int i = dlg.getUserEnteredValue().toInt();
        ur_stacked_widget->setCurrentIndex(i);
    }
    于 2013-03-19T10:39:37.993   回答