Using PySide2 to develop Maya Plug-in Series I: QT Designer to design GUI, pyside-uic to convert. ui file to. py file

Keywords: Python pip Qt Windows

Preliminary preparation:

Install python: https://www.python.org/downloads/

Install PySide2: After installing python, there is a / script folder in the installation directory with pip.exe, cmd execution: pip install PySide, pip install PySide2 (note: Python 2.x corresponds to PySide, Python 3.x corresponds to PySide2)

Start the QT Designer:

1. Search for designer.exe in python installation directory and send it to desktop shortcuts

2. Or search for designer.exe in the Maya (version above 2015) installation directory and send it to desktop shortcuts

Reference resources: Maya Max python PySide integration shiboken version correspondence

QT Designer Design GUI

1. Open designer and select Widget as an example. Note: You can also choose other templete s, Widgets and Main Windows are different. Find the difference between QWidget s and QMain Windows by yourself.

2. Add some controls and save them as test.ui

pyside-uic converts. ui file to. py file

Like designer.exe, pyside-uic.exe, pyside2-uic.exe can also be found in the installation directory of python or Maya.

Tips: cmd path cd is the development path (.ui,.py file path), drag pyside-uic.exe to the cmd window.

cmd command: pyside-uic.exe-o test_ui_pyside.py test.ui

View the use of pyside-uic: pyside-uic.exe-h

Here's how to generate test_ui_pyside.py using Maya 2017 integrated pyside2

Here is the generated code:

 1 # -*- coding: utf-8 -*-
 2 
 3 # Form implementation generated from reading ui file '.\test.ui'
 4 #
 5 # Created: Tue Oct 30 08:03:48 2018
 6 #      by: pyside-uic 0.2.15 running on PySide 1.2.4
 7 #
 8 # WARNING! All changes made in this file will be lost!
 9 
10 from PySide import QtCore, QtGui
11 
12 class Ui_Form(object):
13     def setupUi(self, Form):
14         Form.setObjectName("Form")
15         Form.resize(280, 274)
16         self.verticalLayout = QtGui.QVBoxLayout(Form)
17         self.verticalLayout.setObjectName("verticalLayout")
18         self.pushButton = QtGui.QPushButton(Form)
19         self.pushButton.setObjectName("pushButton")
20         self.verticalLayout.addWidget(self.pushButton)
21         self.pushButton_2 = QtGui.QPushButton(Form)
22         self.pushButton_2.setObjectName("pushButton_2")
23         self.verticalLayout.addWidget(self.pushButton_2)
24 
25         self.retranslateUi(Form)
26         QtCore.QMetaObject.connectSlotsByName(Form)
27 
28     def retranslateUi(self, Form):
29         Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
30         self.pushButton.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
31         self.pushButton_2.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
test_ui_pyside.py
 1 # -*- coding: utf-8 -*-
 2 
 3 # Form implementation generated from reading ui file '.\test.ui'
 4 #
 5 # Created: Thu Nov 01 18:39:09 2018
 6 #      by: pyside2-uic  running on PySide2 2.0.0~alpha0
 7 #
 8 # WARNING! All changes made in this file will be lost!
 9 
10 from PySide2 import QtCore, QtGui, QtWidgets
11 
12 class Ui_Form(object):
13     def setupUi(self, Form):
14         Form.setObjectName("Form")
15         Form.resize(280, 274)
16         self.verticalLayout = QtWidgets.QVBoxLayout(Form)
17         self.verticalLayout.setObjectName("verticalLayout")
18         self.pushButton = QtWidgets.QPushButton(Form)
19         self.pushButton.setObjectName("pushButton")
20         self.verticalLayout.addWidget(self.pushButton)
21         self.pushButton_2 = QtWidgets.QPushButton(Form)
22         self.pushButton_2.setObjectName("pushButton_2")
23         self.verticalLayout.addWidget(self.pushButton_2)
24 
25         self.retranslateUi(Form)
26         QtCore.QMetaObject.connectSlotsByName(Form)
27 
28     def retranslateUi(self, Form):
29         Form.setWindowTitle(QtWidgets.QApplication.translate("Form", "Form", None, -1))
30         self.pushButton.setText(QtWidgets.QApplication.translate("Form", "PushButton", None, -1))
31         self.pushButton_2.setText(QtWidgets.QApplication.translate("Form", "PushButton", None, -1))
test_ui_pyside2.py

The benefit of converting ui files into py files is that they are readable and easy to internationalize in the future, as will be mentioned in subsequent chapters.

Back to the overview: Overview of Maya Plug-in Series Developed with PySide2

Posted by mmitdnn on Tue, 22 Jan 2019 14:00:13 -0800