qt - QStackedWidget 帮助

标签 qt widget

我在我的主窗口上使用 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/

相关文章:

c++ - 子类 QDial 如何停止从 Min 到 Max 的移动?

qt - 制作一个新的小部件并在表单中使用

c++ - WT 小部件未在 boost 线程中更新

c++ - 在 Windows 中调试 QT 5.8 和打开 QFileDialog 时,gdborig.exe 随机崩溃

c++ - 在 C++ 中,如何修改运算符以便在同一条语句中连续调用它两次?

qt - 在 QML 中,(如何)我可以将 MapItemGroup 作为 MapItemView 的委托(delegate)组件?

c++ - Qt 应用程序在运行时找不到共享库

css - 在 HTML 小部件中滚动

Android:如何创建自定义按钮小部件

wordpress - WordPress 小部件(或侧边栏) Hook 是否存在?