Trouble loading Qt ui file

Trouble loading Qt ui file

Anonymous
Not applicable
2,346 Views
3 Replies
Message 1 of 4

Trouble loading Qt ui file

Anonymous
Not applicable

Hey all,

 

I'm trying to load a Qt ui file through python in Max, but it's not working for me. I'm following thi example I found in the docs...

http://help.autodesk.com/view/MAXDEV/2021/ENU/?guid=Max_Python_API_creating_python_uis_html

(scroll down to Loading Qt UI Files) (code pasted below as well)

 

I made sure to create a 'test.ui' file with a QPushButton named 'pushButton' so that I could test the example as simply as possible. However, when I run this code I do not see the UI I created in Qt Designer. Instead  I just see an empty panel. I'd be grateful for anyone who can point out where I'm going wrong.

 

Many thanks.

 

import os
from PySide2.QtWidgets import QVBoxLayout
from PySide2.QtWidgets import QWidget
from PySide2.QtWidgets import QDialog
from PySide2.QtWidgets import QPushButton
from PySide2.QtCore import QFile
from PySide2.QtUiTools import QUiLoader
from pymxs import runtime as rt

class TestDialog(QDialog):
    def __init__(self, parent=QWidget.find(rt.windows.getMAXHWND())):
        QDialog.__init__(self, parent)
        loader = QUiLoader()
        ui_file_path = os.path.join(  os.path.dirname(os.path.realpath(__file__)), 'test_ui.ui')
        ui_file = QFile(ui_file_path)
        ui_file.open(QFile.ReadOnly)
        self.ui = loader.load(ui_file, self)
        ui_file.close()

        layout = QVBoxLayout()
        layout.addWidget(self.ui)
        self.setLayout(layout)
        btn = self.ui.findChild(QPushButton, 'pushButton')
        btn.clicked.connect(self.makeTeapot)

    def makeTeapot(self):
        rt.teapot()
        rt.redrawViews()

def main():
    dlg = TestDialog()
    dlg.show()

if __name__ == '__main__':
    main()
0 Likes
Accepted solutions (1)
2,347 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Accepted solution

OK, figured out what I was doing wrong. I created my ui file as a QDialog. By making a ui file as a QWidget, this works as expected. Oh the process of learning...

Message 3 of 4

Anonymous
Not applicable

Hi, I might have the same issue like yours when I try to load ui file in 3ds max, kinda new, just don't understand what is "making ui file as a QWidget", can you explain more about it ? pls...

0 Likes
Message 4 of 4

Luna_Gu98
Explorer
Explorer

I got the same problem.  I believe @Anonymous was saying when creating a ui file in Qt Designer, you have to choose "Widget" instead of any other templates at the very first.  I solved the problem by changing my
"Main Window" ui file to "Widget" 🙂

Luna_Gu98_0-1684239973799.png