有关QStackedWidget的帮助

Sur*_*dhi 3 qt widget

我在mainWindow上使用QStackedWidget.stackedWidget上的firstPageWidget包含3个按钮.现在如果我按第一页上的第一个按钮,我希望stackedWidget显示第二页面小部件.以下是详细信息

我尝试在我的主窗口中这样连接

connect(firstPageWidget->button1,SIGNAL(clicked()),stackWidget,SLOT(setCurrentIndex(int)));
Run Code Online (Sandbox Code Playgroud)

现在我想知道如何将索引号的值传递给stackWidget来设置currentIndex?

如果我的问题不太明确,请告诉我,我会解释更多.

cha*_*lup 5

您可能需要使用QSignalMapper类:

QSignalMapper mapper = new QSignalMapper(); // don't forget to set the proper parent
mapper->setMapping(firstPageWidget->button1, 2); // 2 can be replaced with any int value
connect(firstPageWidget->button1, SIGNAL(clicked()), mapper, SLOT(map()));
connect(mapper, SIGNAL(mapped(int)), stackWidget, SLOT(setCurrentIndex(int)));
Run Code Online (Sandbox Code Playgroud)