我在我的主窗口上使用 QStackedWidget。 stackedWidget 上的firstPageWidget 包含3 个按钮。现在,如果我按下第一页上的第一个按钮,我希望 stackedWidget 显示第二页小部件。详情如下
我尝试在主窗口中这样连接
connect(firstPageWidget->button1,SIGNAL(clicked()),stackWidget,SLOT(setCurrentIndex(int)));
现在我想知道如何将索引号的值传递给stackWidget来设置currentIndex?
如果我的问题不太清楚,请告诉我,我会解释更多。
最佳答案
您可能需要使用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)));
关于qt - QStackedWidget 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2619885/