适用于OSX 10.6的PyQt的Qt设计器 [英] Qt Designer for PyQt on OSX 10.6

查看:85
本文介绍了适用于OSX 10.6的PyQt的Qt设计器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常喜欢Windows上的Qt Designer来为Python应用程序(使用PyQt4)制作GUI,因此尝试将其安装在Mac上(在OSX 10.6.6下).

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).

至此,我已经成功安装了SIP,Qt4和PyQt4.

At this point, I have successfully installed SIP, Qt4, and PyQt4.

PyQt二进制安装程序(适用于Windows)包括与PyQt一起使用的Qt Designer版本.在OSX上,没有二进制安装程序,只有源代码.所以没有Qt Designer.

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.

Qt网站提供了Qt Creator的下载,但据我所知,它要求您使用C/C ++编写代码.

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 Creator与PyQt一起使用?还是有另一个适用于Mac的PyQt GUI设计器?

Is there a way to make Qt Creator work with PyQt? Or is there another GUI designer for PyQt that works on a Mac?

谢谢! -韦斯利

推荐答案

如果已安装Qt4,则您具有Qt Designer.如果您使用的是qt.nokia.com上的安装程序,则该安装程序应位于/Developer/Applications/Qt中.

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.

Qt Designer本身可以与PyQt一起正常工作. Qt设计器只是吐出描述UI结构的XML.如果将标准Qt与C ++一起使用,则必须运行uic工具从.ui文件生成C ++.同样,对于PyQt4,必须在生成的.ui文件上运行pyuic4才能从中创建python源.

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.

如果您正在寻找一个完整的IDE解决方案,该解决方案可以使用PyQt自动处理所有这些问题,那么我不知道有一个解决方案.我只有一个build_helper.py脚本来处理我的所有.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.

我的所有.ui文件都放入项目根目录中的子文件夹ui中.然后,脚本会创建python源并将其放入"myapp/ui/generated"中.

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'.

例如:

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()

我还有其他一些功能,可以运行pyrcc4进行资源编译,并运行pylupdate4lrelease生成翻译.

I also have a few other functions in there for running pyrcc4 for resource compilation and pylupdate4 and lrelease to generate translations.

这篇关于适用于OSX 10.6的PyQt的Qt设计器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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