Created
June 19, 2019 00:38
-
-
Save whoiscarlo/8669a1f2f74a08752f236ce3b9bacc21 to your computer and use it in GitHub Desktop.
Create QT UI In Maya
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5 import QtWidgets | |
from PyQt5 import QtCore | |
from PyQt5 import QtGui | |
from maya import OpenMayaUI | |
from sip import wrapinstance | |
class Test_UI(QtWidgets.QWidget): | |
def __init__(self, *args, **kwargs): | |
super(Test_UI, self).__init__(*args, **kwargs) | |
self.setParent(self.getMainWindow()) | |
self.setWindowFlags(QtCore.Qt.Window) | |
self.setObjectName('Test_UI_uniqueId') | |
self.setWindowTitle('Test User Interface') | |
self.setGeometry(50, 50, 280, 150) | |
self.initUI() | |
def getMainWindow(self): | |
ptr = OpenMayaUI.MQtUtil.mainWindow() | |
mainWindow = wrapinstance(long(ptr), QtWidgets.QWidget) | |
return mainWindow | |
def initUI(self): | |
self.layout = QtWidgets.QGridLayout(self) | |
self.setLayout(self.layout) | |
self.menuBar = QtWidgets.QMenuBar(parent = self.getMainWindow()) # requires parent | |
self.menu = QtWidgets.QMenu(self) | |
self.menu.setTitle("Menu") | |
self.menuBar.addMenu(self.menu) | |
self.menu.addAction("Menu Item") | |
self.menu.triggered.connect(self.menuAction) | |
self.text = QtWidgets.QLabel(self) | |
self.text.setText("Test Window") | |
self.text.setAlignment(QtCore.Qt.AlignCenter) | |
self.layout.addWidget(self.menuBar, 0, 0, 1, 1) | |
self.layout.addWidget(self.text, 0, 0, 1, 1) | |
def menuAction(self): | |
print("Menu Works.") | |
Test_UI().show() # show UI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment