pyuic的参数,以及如何使用由ui转换的.py文件

这是一个命令行界面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.

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值