Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Show existing QDockWidget instead of initializing new one

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
chrisdawlud
918 Views, 3 Replies

Show existing QDockWidget instead of initializing new one

I have a simple problem with QtDockWidget in PySide2. Whenever I execute my script it creates the UI widget but every new script call creates one more instance of the same UI object instead of showing the already existing one. It's the same situation with demoPySideToolBarQWidget.py example. How do I check and call the UI object which appears under customize ui rollout?hdrimanager_problem.jpg

Tags (3)
3 REPLIES 3
Message 2 of 4
elpie89
in reply to: chrisdawlud

Did you ever found a solution for this?

I have the exact same problem

Message 3 of 4
drew.avis
in reply to: chrisdawlud

You could check to see if the Max main window already holds an instance of your widget, and only create a new instance if it doesn't.  Here's an example of this approach:

 

from PySide2 import QtCore
from PySide2 import QtGui
from PySide2 import QtWidgets
import pymxs
import MaxPlus

def make_cylinder():
    cyl = pymxs.runtime.Cylinder(radius=10, height=30)
    pymxs.runtime.redrawViews()
    return    
    
class PyMaxDockWidget(QtWidgets.QDockWidget):
    def __init__(self, parent=None):
        super(PyMaxDockWidget, self).__init__(parent)
        self.setWindowFlags(QtCore.Qt.Tool)
        self.setWindowTitle('Pyside Qt  Dock Window')
        self.initUI()
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        
    def initUI(self):
        main_layout = QtWidgets.QVBoxLayout()
        label = QtWidgets.QLabel("Click button to create a cylinder in the scene")
        main_layout.addWidget(label)

        cylinder_btn = QtWidgets.QPushButton("Cylinder")
        cylinder_btn.clicked.connect(make_cylinder)
        main_layout.addWidget(cylinder_btn)
        widget = QtWidgets.QWidget()
        widget.setLayout(main_layout)
        self.setWidget(widget)
        self.resize(250, 100)    


def main():
    pymxs.runtime.resetMaxFile(pymxs.runtime.name('noPrompt'))
    mainWindow = MaxPlus.GetQMaxMainWindow()
# check if there's already an instance running dockWidgets = [x for x in mainWindow.children() if x.__class__.__name__ == 'PyMaxDockWidget'] w = None if (len (dockWidgets)>0): w = dockWidgets[0] else: w = PyMaxDockWidget(parent=mainWindow) # Do this if you want to dock the widget initially: # mainWindow.addDockWidget(QtCore.Qt.LeftDockWidgetArea, w) w.setFloating(True) w.show() if __name__ == '__main__': main()


Drew Avis
Content Experience Designer
Message 4 of 4
elpie89
in reply to: drew.avis

thanks

this worked, as I'm working on a larger tool, I need to attach and remove widget dynamically but, I think I found a bug

Can you take a look at this as well?

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report