Has anyone gotten Maya 2018 to load up a .ui file from qtdesigner and show up?

I created a qtdesigner .ui file and am trying to get it to show up in Maya 2018. All that happens is a blank ui pops up and then is closed with no errors. I even added some code to find a child button in my .ui file and set an even on it just to see if it would error but it found it and kept with the same no ui.
Does anyone who has worked with qtdesigner have an example or what to look at that might be causing this?

thanks,

MO

A little more details…
I am able to get the window to show up but is not movable by using python cmds. I have a script ready to use pyside2 but it is the one that will not show the ui and I have no idea why.

Ill include it below:


import shiboken2

# Maya specific libs
from PySide2.QtCore import *
from PySide2.QtUiTools import *
from PySide2.QtWidgets import *
import maya.OpenMayaUI as omui


def get_main_window():
    try:
        mayaMainWindowPtr = omui.MQtUtil.mainWindow()
        mayaMainWindow = shiboken2.wrapInstance(long(mayaMainWindowPtr), QWidget)
    except:
        mayaMainWindow = None
    return mayaMainWindow

main_window = get_main_window()


class Main(QDialog):
    def __init__(self):
        super(Main, self).__init__(main_window)
        self.setParent(main_window)

        ui_file = QFile("T:/utils/VAT/VATUI.ui")
        ui_file.open(QFile.ReadOnly)
        window = QUiLoader().load(ui_file, parent=self)
        ui_file.close()

        btn = window.findChild(QPushButton, 'exportas_button')
        btn.clicked.connect(self.closeEvent)

        window.show()

    def closeEvent(self, event):
        """
        on close, this closes the ui
        """
        super(Main, self).closeEvent(event)
        self.window.close()

You’re showing window, not Main().
Take window.show() out of your __init__ method
Then, when you create your dialog, that’s what you show.

myDlg = Main()
myDlg.show()

[Edit]
Ok, now that the dialog is showing (or at least it does on my machine with the above change), there’s one thing that you should really fix, IMO
Don’t use global variables (like main_window in your example). That means the __init__ for Main has to take a second argument like this def __init__(self, parent):
Also, passing main_window to the super init already sets the parent of your dialog, so you don’t need self.setParent(main_window) So then, when you make your dialog, you pass its parent to it.
Oh yeah, and since you’re calling self.window in your close method, you have to make sure to store the window somewhere.

This is what the dialog and startup looks like after the changes I suggest.

class Main(QDialog):
    def __init__(self, parent):
        super(Main, self).__init__(parent)

        ui_file = QFile("T:/utils/VAT/VATUI.ui")
        ui_file.open(QFile.ReadOnly)
        self.window = QUiLoader().load(ui_file, parent=self)
        ui_file.close()

        btn = self.window.findChild(QPushButton, 'exportas_button')
        btn.clicked.connect(self.closeEvent)

    def closeEvent(self, event):
        """ on close, this closes the ui """
        super(Main, self).closeEvent(event)
        self.window.close()

main_window = get_main_window()
md = Main(main_window)
md.show()

There are still some other issues (like self.window not being in a layout, so it doesn’t show properly), but that’s for your next question! :slight_smile:

That makes sense, I didn’t realize the code was so sloppy.
So does qdialog need another layout as well to add my .ui dialog to???

Also, in order to use pyside2, do I have to convert the .ui file to .py? Cuz I thought using Pyside2 did this on the fly.

MO

“Sloppy” makes it sound bad, and it’s not bad at all. You’re learning. It happens.
You just happened to do something that’s a pet peeve of mine (the global variable), and I just got carried away with explaining the changes to fix that.

Yep! Specifically a QLayout.

You can, and absolutely should, leave it as a .ui file. Almost every tool at work uses .ui files.

I’m still having issues with getting the .ui content from loading into the window I create in Maya. Is there something specific I need to do in QTDesigner in the setup of the QDialog or is this likely still a maya python pyside2 setup that I am likely missing?

import shiboken2

# Maya specific libs
from PySide2.QtCore import *
from PySide2.QtUiTools import *
from PySide2.QtWidgets import *

import maya.OpenMayaUI as omui
import maya.cmds as cmds


def get_main_window():
    try:
        mayaMainWindowPtr = omui.MQtUtil.mainWindow()
        mayaMainWindow = shiboken2.wrapInstance(long(mayaMainWindowPtr), QWidget)
    except:
        mayaMainWindow = None
    return mayaMainWindow


class vat_ui(QDialog):
    def __init__(self, *args, **kwargs):
        super(vat_ui, self).__init__(*args, **kwargs)

        self.setParent(get_main_window())
        self.setWindowFlags(Qt.Window)
        self.setWindowTitle('AGS Vehicle Assembly Tool')
        self.setObjectName('AGS_VAT_UI')
        self.main_layout = QVBoxLayout()
        self.initUI()

    def initUI(self):
        ui_file = QFile("T:/utils/VAT/VATUI.ui")
        ui_file.open(QFile.ReadOnly)
        self.qtui = QUiLoader().load(ui_file, parentWidget=self)
        ui_file.close()

        btn = self.qtui.findChild(QPushButton, 'exportas_button')
        btn.clicked.connect(self.closeEvent)

    def closeEvent(self, event):
        """
        on close, this closes the ui
        """
        self.close()


def main():
    old_ui = omui.MQtUtil.findControl('AGS_VAT_UI')
    try:
        old_ui.deleteLater()
        old_ui = None
    except AttributeError as e:
        pass

    ui = vat_ui()
    ui.setObjectName('AGS_VAT_UI')
    ui.show()
    return ui

if __name__ == '__main__':
    main()

You are tantalizingly close. You created a layout … but then you didn’t do anything with it!

So look at the documentation for the QVBoxLayout constructor. Then, look at QLayout in the docs.

You can also try converting your .ui to a .py and looking at the code in there just to see how to use layouts.

Yep, got it and cannot thank you enough…

self.setParent(get_main_window())
self.setWindowFlags(Qt.Window)
self.setWindowTitle('AGS Vehicle Assembly Tool')
self.setObjectName('AGS_VAT_UI')
self.setWindowFlags(Qt.Window | Qt.WindowStaysOnTopHint)
self.setFixedSize(398, 235)
self.setContentsMargins(0, 0, 0, 0)
self.main_layout = QVBoxLayout()
self.main_layout.setContentsMargins(0, 0, 0, 0)
self.initUI()
self.setLayout(self.main_layout)
self.main_layout.addWidget(self.qtui)

Thanks tfox_TD