Maya 2017 Dockable windows and custom icons

qt
maya

#1

In Maya 2017 you need to inherit from MayaQWidgetDockableMixin to create a dockable window. This in turn parents your custom window (a QMainWindow in my case) to a workspaceControl. I can create a custom icon for my widow if I don’t set it to dockable, but as soon as I do the custom icon is destroyed, and the workspaceControl takes over. There is no access to the icon through the workspaceControl flags. Has anyone solved this?


#2

Have you tried getting the QObject/QWidget for the workspaceControl? Latest PyMEL has utility functions to get them for PySide and PyQt. Send me some UI code. I’ll suffer through it with you. :smiley:


#3

I’m taking a swing from that direction. I will keep you posted.


#4

Well, that was fun… So, when you set dockable to True, the widget gets buried in several layers of other widgets, which requires you to change the widget you’re setting the icon for. So just need to override the show() method to set the window icon on the proper widget when dockable=True:

class testDockUI(mmi.MayaQWidgetDockableMixin, QtWidgets.QMainWindow):

    def __init__(self, parent=None):

        super(testDockUI, self).__init__(parent)
        
        self.setWindowTitle('Test Dock UI')

        pixMap = QtGui.QPixmap(12, 12)
        pixMap.fill(QtGui.QColor('red'))
        self.iconData = QtGui.QIcon(pixMap)
        
        self.setWindowIcon(self.iconData)
        
    def show(self, *args, **kwargs):
        
        super(testDockUI, self).show(*args, **kwargs)
        
        if 'dockable' in kwargs:
            if kwargs['dockable']:
                QtWidgets.QWidget.setWindowIcon(self.parent().parent().parent().parent().parent(), self.iconData)

Unfortunately, after docking/undocking, the icon gets reset. Can’t figure out where that’s happening to set it back again.


#5

Thanks for looking at this Mile. It pains me to see so much digging for the parent :slight_smile:
There should be a dockTriggered event or something like that to look for. I’m going to work with this a bit and will report back.


#6

I did find this method which seems to eliminate the need for parent(). However it requires you wrap a workspaceControl as a QT object.
“”"
Docking concept courtesy of Lior ben horin
“”"
name = ‘Chickens’
main_control = pm.workspaceControl(name, iw=300, ttc=[“AttributeEditor”, -1], li=False, mw=True, wp=‘preferred’, label = “Chickens”)
control_widget = omui.MQtUtil.findControl(name)

control_wrap = wrapInstance(long(control_widget), QtWidgets.QWidget)
control_wrap.setStyleSheet(“background-color:black;”)
control_wrap.setAttribute(QtCore.Qt.WA_DeleteOnClose)

pixMap = QtGui.QPixmap(12, 12)
pixMap.fill(QtGui.QColor(‘blue’))
iconData = QtGui.QIcon(pixMap)
v = control_wrap.window()
v.setWindowIcon(iconData)


#7

Ah, gotcha. So you’re just using the workspaceControl command now instead of the MayaQWidgetDockableMixin. Definitely like that approach more. :smiley:


#8

I just realized that sets the icon for several Maya windows. I think I need to step down by one.


#9

It looks like the parent() method does the same.


#10

Have you guys been successful in using MayaQWidgetDockableMixin with Maya 2018.1?
My UI is quite complex and doesn’t update properly. If I dick/dock it around back and forth, eventually the UI is frozen. If I grab the edge of the UI and slightly resize it, a force-refresh seems to be initiated. But not always is the UI responsive and will require another resize nudge in order to properly update. Is this just me - or does anyone else see this too?


#11

I moved away from the MayaQWidgetDockableMixin. I’m using something like this now. https://gist.github.com/liorbenhorin/69da10ec6f22c6d7b92deefdb4a4f475


#12

I’m currently running into this. The UI doesn’t update when I repopulate a QTreeView and it won’t take any of my custom style sheets.