PyQt4 Qt Designer 制作动态 GUI [英] PyQt4 Qt Designer making dynamic GUIs

查看:59
本文介绍了PyQt4 Qt Designer 制作动态 GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出一种使用 Qt Designer 制作动态 GUI 的方法.例如,假设我有一个水平布局的主窗口.我的一侧有一个按钮,另一侧有一个空白区域.当我单击按钮时,空白区域将填充我在 Qt Designer 中制作的小部件.当再次按下按钮时,小部件将被替换为我在 Qt 设计器中制作的另一个小部件.我是否必须制作所有小部件以填充空白区域和自定义小部件?

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.

请帮忙

推荐答案

没关系,想通了.真的很简单.使用 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.

这篇关于PyQt4 Qt Designer 制作动态 GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆