简体   繁体   English

Qt中的动态用户界面

[英]Dynamic user interfaces in Qt

I have a button, and a layout, which loads a custom QWidget . 我有一个按钮和一个布局,它加载自定义QWidget I want to change the widget in the layout into another sample widget when clicking a button. 我想在单击按钮时将布局中的窗口小部件更改为另一个示例窗口小部件。 The previous widget should be completely replaced by the new widget. 上一个小部件应该完全被新小部件替换。 How could I achieve such an effect? 我怎么能达到这样的效果?

Source Code: http://paste.opensuse.org/51831462 源代码: http//paste.opensuse.org/51831462

QStackedWidget is perfect for what you want to achieve. QStackedWidget非常适合您想要实现的目标。

You will have to redesign a bit your code, but the result will be simpler to understand and to maintain. 您将不得不重新设计一些代码,但结果将更容易理解和维护。 You just have to change the current widget of the QStackedWidget when the button is clicked. 您只需在单击按钮时更改QStackedWidget的当前窗口小部件。

You could try with setCentralWidget(). 您可以尝试使用setCentralWidget()。 Could you include your source code in your question? 你可以在你的问题中包含你的源代码吗?

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

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