如何在 QtDesigner 中设计的主窗口类中实现对话框?
我正在编写一个小应用程序(学习 Python 和 PyQt),它有一个“关于”框。我在 QtDesigner 中设计了 QMainWindow 并设法使其工作。我还将 QtDesigner 中的“关于”框设计为对话框。
我使用 pyuic4 将 .ui 文件转换为 .py 文件,即 main.py 和 about-dialog.py
但是,如何从主应用程序“调用”about 对话框?该函数应该是什么样子?我尝试放置:
dialog = ui_aboutDialog.Ui_aboutDlg()
dialog.exec_()
但是,它告诉我关于对话框没有“exec”属性(与 .show() 相同)。
这是 aboutDialog 类的开头:
class Ui_aboutDlg(object):
def setupUi(self, aboutDlg):
aboutDlg.setObjectName(_fromUtf8("aboutDlg"))
aboutDlg.resize(400, 262)
...
我认为这个 setupUi 有问题,它应该是 __init__,但尝试这也没有产生任何结果。
帮助?
I'm writing a small app (learning Python and PyQt) that has an "About" box. I've designed the QMainWindow in QtDesigner and managed to make it work. I've also designed the About box in the QtDesigner as a dialog.
I used pyuic4 to convert both .ui files to .py files, the main.py and about-dialog.py
However, how do I "call" the about dialog from the main app? What should the function look like? I tried putting:
dialog = ui_aboutDialog.Ui_aboutDlg()
dialog.exec_()
However, it gives me that about dialog has no "exec" attribute (same for .show()).
Here is the beginning of the aboutDialog class:
class Ui_aboutDlg(object):
def setupUi(self, aboutDlg):
aboutDlg.setObjectName(_fromUtf8("aboutDlg"))
aboutDlg.resize(400, 262)
...
I think something is wrong with this setupUi and that it should rather be __init__, but trying that yielded no results either.
Help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仔细阅读教程。 pyuic4 工具不会为您创建完整的对话框;它只会提供一种设置现有对话框的方法。
Read the tutorial carefully. The pyuic4 tool won't make a full dialog for you; it'll only provide a method that sets up an already existing dialog.