pyuic的参数,以及如何使用由ui转换的.py文件
来源:互联网 发布:安卓锁机软件生成器 编辑:程序博客网 时间:2024/06/05 17:17
这是一个命令行界面pyuic4 UIC模块。该命令具有以下语法:
pyuic4 [options] .ui-file
Pyuic4 (选项) .ui -o file
The full set of command line options is:
-h, --help
A help message is written to stdout.
--version
The version number is written to stdout.
-i <N>, --indent <N>
The Python code is generated using an indentation of <N> spaces. If <N> is 0 then a tab is used. The default is 4.
-o <FILE>, --output <FILE>
The Python code generated is written to the file <FILE>.
-p, --preview
The GUI is created dynamically and displayed. No Python code is generated.
-w, --pyqt3-wrapper
The generated Python code includes a small wrapper that allows the GUI to be used in the same way as it is used in PyQt v3.
-x, --execute
The generated Python code includes a small amount of additional code that creates and displays the GUI when it is executes as a standalone application.
--from-imports
Resource modules are imported using from . import rather than a simple import.
--resource-suffix <SUFFIX>
The suffix <SUFFIX> is appended to the basename of any resource file specified in the .ui file to create the name of the Python module generated from the resource file by pyrcc4. The default is _rc. For example if the .ui file specified a resource file called foo.qrc then the corresponding Python module is foo_rc.
Using the Generated Code
The code that is generated has an identical structure to that generated by Qt’s uic and can be used in the same way.
The code is structured as a single class that is derived from the Python object type. The name of the class is the name of the toplevel object set in Designer with Ui_ prepended. (In the C++ version the class is defined in the Ui namespace.) We refer to this class as the form class.
The class contains a method called setupUi(). This takes a single argument which is the widget in which the user interface is created. The type of this argument (typically QDialog, QWidget or QMainWindow) is set in Designer. We refer to this type as the Qt base class.
In the following examples we assume that a .ui file has been created containing a dialog and the name of the QDialog object is ImageDialog. We also assume that the name of the file containing the generated Python code is ui_imagedialog.py. The generated code can then be used in a number of ways.
The first example shows the direct approach where we simply create a simple application to create the dialog:
import sys
from PyQt4.QtGui import QApplication, QDialog
from ui_imagedialog import Ui_Image
Dialogapp = QApplication(sys.argv)
window = QDialog()
ui = Ui_ImageDialog()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())
The second example shows the single inheritance approach where we sub-class QDialog and set up the user interface in the __init__() method:
from PyQt4.QtGui import QDialog
from ui_imagedialog import Ui_ImageDialog
class ImageDialog(QDialog):
def __init__(self):
QDialog.__init__(self)
# Set up the user interface from Designer.
self.ui = Ui_ImageDialog()
self.ui.setupUi(self)
# Make some local modifications.
self.ui.colorDepthCombo.addItem("2 colors (1 bit per pixel)")
# Connect up the buttons.
self.ui.okButton.clicked.connect(self.accept)
self.ui.cancelButton.clicked.connect(self.reject)
The third example shows the multiple inheritance approach:
from PyQt4.QtGui import QDialog
from ui_imagedialog import Ui_ImageDialog
class ImageDialog(QDialog, Ui_ImageDialog):
def __init__(self):
QDialog.__init__(self)
# Set up the user interface from Designer.
self.setupUi(self)
# Make some local modifications.
self.colorDepthCombo.addItem("2 colors (1 bit per pixel)") # Connect up the buttons. self.okButton.clicked.connect(self.accept) self.cancelButton.clicked.connect(self.reject)
It is also possible to use the same approach used in PyQt v3. This is shown in the final example:
from ui_imagedialog import ImageDialogclass MyImageDialog(ImageDialog): def __init__(self): ImageDialog.__init__(self) # Make some local modifications. self.colorDepthCombo.addItem("2 colors (1 bit per pixel)") # Connect up the buttons. self.okButton.clicked.connect(self.accept) self.cancelButton.clicked.connect(self.reject)
For a full description see the Qt Designer Manual in the Qt Documentation.
- pyuic的参数,以及如何使用由ui转换的.py文件
- Python笔记004——pycharm下配置pyuic和使用pyuic将.ui转成.py
- pycharm中如何将ui文件转化为py文件,以及Pycharm和QtDesigner的集合
- Ubuntu(Linux) PyQt5 QtUIFile 转换为 PythonModule (pyuic.py/pyuic脚本)
- PythonUI_QtDesigner的ui文件转为py文件
- pyqt下.ui文件转换为对应.py文件的知识整理
- .ui文件转换成.py文件
- 使用pyside+designer将.ui文件转化为.py文件的两种方法
- qt designer设计的.ui文件转.py文件
- template.py-for以及if的使用
- 关于python中将py文件转换成exe文件的问题(使用py2exe)
- python的.py文件如何生成
- python的py文件转换成exe文件
- 8行代码实现ui文件到py文件转换
- 如何将Qt Designer 产生的*.UI文件转换成QT可以使用的*.H和*.CPP
- 如何将Qt Designer 产生的*.UI文件转换成QT可以使用的*.H和*.CPP
- 如何将Qt Designer 产生的*.UI文件转换成QT可以使用的*.H和*.CPP
- 如何将Qt Designer 产生的*.UI文件转换成QT可以使用的*.H和*.CPP
- Android开发模板------SlidingPaneLayout、Navigation Drawer的基本介绍
- Java CompletionService 理解
- Java Bean详细的说明
- jstl 详解
- 在oracle里,如何取得本周、本月、本季度、本年度的第一天和最后一天的时间
- pyuic的参数,以及如何使用由ui转换的.py文件
- 新建jsp注意的问题
- 燕过留声:由 Activity 和 Fragment 的通信方法想到的【WIP】
- ocp-429
- ocp-430
- 我是怎么招聘程序员的
- Jquery基础
- 开博客
- 实现不同的日志不同的输出