使用 pyside-uic 生成 Python 代码
如何从 QtDesigner 文件生成 python 代码? 我找到了 pyside-uic 但找不到语法示例。 我用spyder运行win7和pythonxy。
How can I generate python code from a QtDesigner file ?
I found pyside-uic but I can't find an example for the syntax.
I run win7 and pythonxy with spyder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
pyside-uic 或多或少与 pyuic4 相同,因此手册页指定:
我通常这样使用它:
pyside-uic is more or less identical to pyuic4, as such the man page specifies:
I usually use it like this:
刚刚尝试了 Pyside 的 QUILoader,工作正常:
我使用 Eclipse 和 QTDesigner 创建 .ui 文件(右键单击模块,“新建 -> 其他..”,选择“Qt Designer -> Qt Designer Form”)。不需要显式的 uic 调用。
Just tried Pyside's QUILoader, works fine:
I used Eclipse and QTDesigner to create the .ui file (right-click on module, "New -> Other..", choose "Qt Designer -> Qt Designer Form"). No explicit uic call is needed.
这就是我一直在做的事情,而且效果很好(据我所知)
is what I've been doing and it's working fine (as far as I know)
您可以使用这种方式加载UI,还可以获取form_class以及基类作为返回类型...但是如果您不想转换,否则是的,以下是正确的方法。
You can use this way to load the UI and can also get form_class as well as the base class as return type... but if you do not want to convert, otherwise Yes the following is the correct way.
QUiLoader 类将完成这项工作,而无需创建中间文件。
http://www.pyside.org/docs/pyside/PySide/QtUiTools /QUiLoader.html
QUiLoader class will do the job without making an intermediate file.
http://www.pyside.org/docs/pyside/PySide/QtUiTools/QUiLoader.html
阅读文档。在这种特殊情况下,http://www.riverbankcomputing.co。 uk/static/Docs/PyQt4/pyqt4ref.html#pyuic4:
Read the documentation. In this particular case, http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#pyuic4:
PySide 团队目前不鼓励使用 QtUiTools(如另一个答案中所建议的)。
请在此处阅读完整故事:https://groups.google.com/论坛/?fromgroups=#!topic/pyside/_s1HPe6XTZs
Using QtUiTools (as suggested in another answer) is currently discouraged by the PySide team.
Read the full story here: https://groups.google.com/forum/?fromgroups=#!topic/pyside/_s1HPe6XTZs
查看 C:\Python27\Lib\site-packages\PySide\scripts\uic.py (或者安装了 python 的任何地方)。如果您查看该脚本,您可以看到手册页中标记和描述的选项(我不知道如何在 Windows 上正确查看。建议感谢。)这里 http://manpages.ubuntu.com/manpages/precise/man1/pyside-uic.1.html
我在尝试查看 C:\Python27\Lib\site-packages\pysideuic\pyside-uic.1 时感到困惑,因为我认为这一定是正在调用的文件。由于所有额外的字符,即使尝试将其视为手册页对我来说也是不可能的。你不能通过猜测哪些字符是多余的、哪些不是多余的来学习语法!
在 Windows 上,您当然可以使用批处理文件自动执行此操作,方法是保存带有上述行(下面供参考)和 .bat 扩展名(如 uic_generator.bat)的文本文件。
pyside-uic MyWindow.ui -o MyWindow.py
Look at C:\Python27\Lib\site-packages\PySide\scripts\uic.py (or wherever you have python installed). If you look at that script you can see the options labelled and described as in the man page (Which I don't know how to view properly on windows. Tips appreciated.) here http://manpages.ubuntu.com/manpages/precise/man1/pyside-uic.1.html
I got confused for a while trying to look at C:\Python27\Lib\site-packages\pysideuic\pyside-uic.1 as I thought that must be the file that is being called. Even trying to view that as a manual page is impossible for me because of all the extra characters. You can't learn syntax by trying to guess at which characters are extra and which ones aren't!
On windows you can automate this with a batch file of course by saving a text file with the above mentioned line(below for reference) with .bat extension like uic_generator.bat.
pyside-uic MyWindow.ui -o MyWindow.py