Creating UI Components in PyQt for Maya and Unreal 02

Posted by


In this tutorial, we will continue to explore how to create PyQt interfaces for both Maya and Unreal Engine, focusing specifically on working with UI components in our applications. PyQt is a set of Python bindings for the Qt application framework, allowing us to create powerful and customizable user interfaces for our projects. By utilizing PyQt, we can enhance the functionality and user experience of our Maya and Unreal projects.

To get started, make sure you have Python installed on your machine and that you have PyQt and PyQt for Maya and Unreal installed as well. To install PyQt, you can use pip by running the following command:

pip install pyqt5

Next, we will create a basic PyQt application with a simple UI component using the Qt designer. Open Qt designer and create a new window (File > New > Main Window). Add a QLabel component to the window and set its text property to "Hello, World!". Save the file as ui_component.ui.

Now, we need to convert the UI file to Python code using the pyuic5 command-line tool. Navigate to the directory containing ui_component.ui and run the following command:

pyuic5 -o ui_component.py ui_component.ui

This will generate a Python script ui_component.py that defines the UI layout and components. We can now integrate this script into our Maya and Unreal projects.

For Maya:
Create a new Python script in Maya and import the ui_component.py script generated earlier. Next, create a new instance of the Ui_MainWindow class from the imported script and set it as the central widget of the Maya window. Here is an example code snippet:

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from ui_component import Ui_MainWindow

app = QApplication(sys.argv)
window = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())

Run the script in Maya and you should see a new window displaying the text "Hello, World!".

For Unreal Engine:
Create a new Python script in Unreal Engine and import the ui_component.py script. Use Unreal’s Slate UI framework to create a new widget and set it as the root of the Unreal UI. Here is an example code snippet:

import unreal

# Importing generated UI code
import ui_component

# Create a new PyQt widget
widget = ui_component.Ui_MainWindow()
widget.setupUi()

# Create a new Slate widget
slate_widget = unreal.WidgetTree.create_slate_widget()
slate_widget.set_content(widget.pyqt_widget)

# Add the Slate widget to the Unreal UI
unreal.WidgetTree.set_content(slate_widget)

Run the script in Unreal Engine and you should see a new UI component displaying the text "Hello, World!".

By following these steps, you can easily work with UI components in your PyQt applications for both Maya and Unreal Engine. PyQt provides a wide range of UI components that can be customized and integrated into your projects to enhance the user experience and functionality. Experiment with different components and layouts to create unique and interactive interfaces for your projects.

0 0 votes
Article Rating
5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@harshitsingh7631
2 months ago

Heya, thanks for the tutorial.
I have a question, after loading a .UI file, I can't seem to resize it properly, I have a custom UI with maximum width and height set.
When I resize the window, it just doesn't resize the ui with it.

@timetosleep8055
2 months ago

Maya has no support for PySide6? I tried but it keeps complaining about module not found. Tried to manual install them into Maya but couldn't even launch Maya anymore. Guess I stick to PySide2 then.

@lusinamendel5656
2 months ago

7:00 there is only [def closeWindow(self): ] no [def colse(self):] but how could it workes with line39 [self.btn_close.clicked.connect(self.close)] ?

@beccafett4582
2 months ago

I keep getting this error when I try to run the Maya portion:

# Error: Unable to open/read ui device

# # Traceback (most recent call last):

# # File "<maya console>", line 4, in <module>

# # File "D:MayaScriptsLessonsPyQTForMayaAndUnrealMayaUITemplate.py", line 72, in <module>

# # openWindow()

# # File "D:MayaScriptsLessonsPyQTForMayaAndUnrealMayaUITemplate.py", line 67, in openWindow

# # MayaUITemplate.window = MayaUITemplate(parent = mayaMainWindow)

# # File "D:MayaScriptsLessonsPyQTForMayaAndUnrealMayaUITemplate.py", line 27, in _init_

# # self.widget = QtUiTools.QUiLoader().load(self.widgetPath + 'mainWidget.ui')

# # RuntimeError: Unable to open/read ui device

@zibozhang5898
2 months ago

i‘m sure the UI parent is correctly set, but I still got an empty window…..