简体   繁体   English

将菜单项链接到Qt Creator中的不同小部件

[英]Link the menu items to different widgets in Qt Creator

I have created several menu items in the Qt creator, for example : Item X Item Y Item Z 我在Qt创建器中创建了几个菜单项,例如: Item X Item Y Item Z
after creating the menu items, I created different classes with different ui for each item - for example Item_x.cpp Item_x.h and Item_X.ui and added my content to each one 创建菜单项后,我为每个项目创建了具有不同ui的不同类-例如Item_x.cpp Item_x.hItem_X.ui ,并将我的内容添加到每个Item_X.ui

now I want to be able to link Item X to Item_x.ui so when the user clicks on the Item X that specific content is loaded . 现在,我希望能够将Item X链接到Item_x.ui以便当用户单击Item X ,将加载特定内容。 The other issue is that I already have a mainwindow.ui and the menu is set up there. 另一个问题是我已经有一个mainwindow.ui ,并且菜单在那里设置。
I am not sure how to connect each Item to its ui, so when the user clicks Item X the Item_x.ui content appears 我不确定如何将每个Item连接到它的ui,因此当用户单击Item X ,出现Item_x.ui内容

There are few possible solutions. 解决方案很少。 May be in your situation QStackedWidget is the best one. 可能在您的情况下QStackedWidget是最好的之一。 You can put instance of QStackedWidget in your mainwindow. 您可以在主窗口中放入QStackedWidget实例。 After it you can append in this QStackedWidget all your three screens (just call addWidget method for each window on the initialization step of your application). 之后,您可以在此QStackedWidget中添加所有三个屏幕(只需在应用程序的初始化步骤中为每个窗口调用addWidget方法)。 After it, each time user click on item on main menu, your application will change current visible screen in QStackedWidget (you have to implement code for it, of course). 之后,每次用户单击主菜单上的项目,您的应用程序都会更改QStackedWidget中的当前可见屏幕(当然,您必须为其实现代码)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM