PyQt4 Qt Designer 制作动态 GUI
我正在尝试找出一种使用 Qt Designer 制作动态 GUI 的方法。例如,假设我有一个水平布局的主窗口。我的一侧有一个按钮,另一侧有一个空白区域。当我单击该按钮时,空白区域将填充我在 Qt Designer 中制作的小部件。当再次按下该按钮时,该小部件将被我在 Qt Designer 中制作的另一个小部件替换。我是否必须制作所有小部件来填充空白区域,自定义小部件?
我尝试将父级设置为空区域,但在第二次更改时我得到了这个
QLayout: Attempting to add QLayout "" to QWidget "t2", which already has a layout
所以然后我尝试删除布局,但仍然看到旧的小部件位于新的小部件下方,并且布局现在一团糟。
请帮忙
I'm trying to figure out a way of using Qt Designer to make a dynamic GUI. For example, let's say I have a main window with a horizontal layout. I have a push button on one side and an empty area on the other. When I click the button the empty area will be filled with a widget that I've made in Qt Designer. When the button is pressed again the widget will be replaced with another widget that I've made in Qt Designer. Would I have to go about making all my widgets, to fill the empty area, custom widgets?
I've tried setting the parent to the empty are, but on the second change I get this
QLayout: Attempting to add QLayout "" to QWidget "t2", which already has a layout
So then I tried deleting the layout but still see the old widget underneath the new one and the layout is now messed up.
help please
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系,想通了。真的很简单。使用 QStackedWidget 并将 Qt Designer 中创建的 UI 包装在继承自 QWidget 的类中。
Never mind, figured it out. Simple really. Use QStackedWidget and as for the UIs made in Qt Designer wrap that in a class that inherits from QWidget.