lundi 20 avril 2015

Autodesk Maya model panel resize event (PySide, PyQt)

I'm writing a simple tool menu for Maya, and I'd like to stick it to the border of model panel (perspective).

from PySide import QtCore, QtGui
from maya import OpenMayaUI as omui
from shiboken import wrapInstance

class TestWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent = self.getMayaWindow())

        self.setWindowFlags(QtCore.Qt.Tool | QtCore.Qt.FramelessWindowHint)
        self.setFixedSize(100, 100)

        panelPtr = omui.MQtUtil.findControl('modelPanel4')
        panel = wrapInstance(long(panelPtr), QtGui.QWidget) 
        position =  panel.mapToGlobal(panel.pos())
        self.move(position.x(), position.y() + panel.geometry().height() / 2 - self.geometry().height() / 2)

        mainLayout = QtGui.QVBoxLayout(self)
        button = QtGui.QPushButton('CLOSE')
        button.setFixedSize(80, 80)

    def getMayaWindow(self):
        ptr = omui.MQtUtil.mainWindow()
        return wrapInstance(long(ptr), QtGui.QWidget)

w = TestWidget()

The main widget is positioned exactly where I want when it is created (horisontally on the left side of model panel, vertically - in the middle of model panel).

I need to reposition it accordingly when the model panel is resized, but model panel does not emit "resized()" signal. I'd appreciate any advise.

Aucun commentaire:

Enregistrer un commentaire