如何从Qdialog更改QStackedWidget索引
How to change QStackedWidget index from Qdialog
我的应用程序在菜单栏中有一个"actionhelp",当点击打开一个QDialog,其中包含一个ok按钮在主窗口的另一边,我有一个QStackedWidget所以我的问题是如何改变堆叠小部件的索引,当我按下ok按钮在QDialog??
信号和槽位。将ok按钮发出的信号(或在关闭后检查QDialog::Accepted时发出您自己的信号)连接到将改变QStackedWidget中的索引的插槽。
示例代码:
在主方法中创建并连接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);
}
}
假设您在对话框中有一个行编辑,并且您希望根据行编辑值(或旋转框)更改堆叠小部件的索引:
//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);
}
相关文章:
- 检测 QStackedWidget 中的小部件更改
- QStackedWidget 具体如何使用它?
- QStackedWidget in a QtContainer中的双重删除
- QSTACKEDWIDGET区域在Child Widget Line编辑中在ESC上清除
- qt中显示QStackedWidget项的延迟
- 在 QStackedWidget 项中浏览键盘
- 如何在qt中使用QStackedwidget从一个ListWidget导航到另一个ListWidget
- 更改QStackedWidget中的小部件
- QT Creator语言 - QStackedWidget pages proglem
- 如何从包含的小部件更改QStackedWidget的索引
- 如何从Qdialog更改QStackedWidget索引
- 如何使用css更改QStackedWidget内部QWidget的背景颜色