macos OSX 10.6 上 PyQt 的 Qt 设计器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5044353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Qt Designer for PyQt on OSX 10.6
提问by Wesley
I liked Qt Designer on Windows so much for making GUIs for Python applications (using PyQt4) that I went and tried to install it on my Mac (under OSX 10.6.6).
我非常喜欢 Windows 上的 Qt Designer,因为它为 Python 应用程序(使用 PyQt4)制作 GUI,我去尝试将它安装在我的 Mac 上(在 OSX 10.6.6 下)。
At this point, I have successfully installed SIP, Qt4, and PyQt4.
至此,我已经成功安装了SIP、Qt4和PyQt4。
The PyQt binary installers (for Windows) include a version of Qt Designer that works with PyQt. On OSX, there is no binary installer, just source. So no Qt Designer.
PyQt 二进制安装程序(适用于 Windows)包括与 PyQt 配合使用的 Qt Designer 版本。在 OSX 上,没有二进制安装程序,只有源代码。所以没有 Qt 设计师。
The Qt website offers Qt Creator as a download, but as far as I can tell, it requires that you're writing code in C/C++.
Qt 网站提供 Qt Creator 作为下载,但据我所知,它要求您使用 C/C++ 编写代码。
Is there a way to make Qt Creator work with PyQt? Or is there another GUI designer for PyQt that works on a Mac?
有没有办法让 Qt Creator 与 PyQt 一起工作?或者是否有另一个适用于 Mac 的 PyQt GUI 设计器?
Thanks! -Wesley
谢谢!-卫斯理
回答by Grant Limberg
If you've installed Qt4, then you have Qt Designer. If you used the installer from qt.nokia.com, it should be in /Developer/Applications/Qt.
如果您已经安装了 Qt4,那么您就有了 Qt Designer。如果您使用了 qt.nokia.com 上的安装程序,它应该在 /Developer/Applications/Qt 中。
Qt Designer itself works just fine with PyQt. Qt designer just spits out XML describing the UI structure. If you were using standard Qt with C++, you would have to run the uic
tool to generate C++ from the .ui files. Likewise, with PyQt4, you must run pyuic4
on the generated .ui file to create python source from it.
Qt Designer 本身与 PyQt 配合得很好。Qt 设计器只是吐出描述 UI 结构的 XML。如果您在 C++ 中使用标准 Qt,则必须运行该uic
工具以从 .ui 文件生成 C++。同样,对于 PyQt4,您必须pyuic4
在生成的 .ui 文件上运行才能从中创建 python 源代码。
If you're looking for a full IDE solution that handles all of this with PyQt automatically, I'm unaware of the existence of one. I just have a build_helper.py
script that processes all of my .ui files and places them in the appropriate place in the python package I'm developing. I run the build helper script before running the actual main program to ensure that the generated code is up to date.
如果您正在寻找一个完整的 IDE 解决方案,它可以自动处理 PyQt 的所有这些,我不知道存在一个。我只有一个build_helper.py
脚本来处理我所有的 .ui 文件并将它们放在我正在开发的 python 包中的适当位置。我在运行实际的主程序之前运行构建帮助程序脚本,以确保生成的代码是最新的。
All of my .ui files go into a subfolder ui
in the project root. The script then creates python source and places it into 'myapp/ui/generated'.
我所有的 .ui 文件都进入ui
项目根目录中的一个子文件夹。然后脚本创建 python 源并将其放入“myapp/ui/generated”。
For example:
例如:
import os.path
from PyQt4 import uic
generated_ui_output = 'myapp/ui/generated'
def process_ui_files():
ui_files = (glob.glob('ui/*.ui'),
glob.glob('ui/Dialogs/*.ui'),
glob.glob('ui/Widgets/*.ui')))
for f in ui_files:
out_filename = (
os.path.join(
generated_ui_output,
os.path.splitext(
os.path.basename(f))[0].replace(' ', '')+'.py')
)
out_file = open(out_filename, 'w')
uic.compileUi(f, out_file)
out_file.close()
if __name__ == '__main__':
process_ui_files()
I also have a few other functions in there for running pyrcc4
for resource compilation and pylupdate4
and lrelease
to generate translations.
我也有在那里一些其他的功能,运行pyrcc4
资源编译和pylupdate4
与lrelease
产生的翻译。