EDIT: Forgot to mention that I’m working with Maya
Is there an easy way to have a button, made in QT Designer, execute a function?
For example:
I have a window with just one button. When the button is clicked, I would like the PiratePrint function to be called.
from maya import OpenMayaUI as omui
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtUiTools import *
from shiboken import wrapInstance
import maya.cmds as cmds
def CreateUI():
mayaMainWindowPtr = omui.MQtUtil.mainWindow()
mayaMainWindow = wrapInstance(long(mayaMainWindowPtr), QWidget)
loader = QUiLoader()
file = QFile("D:/myAwesomeButton.ui")
file.open(QFile.ReadOnly)
ui = loader.load(file, parentWidget = mayaMainWindow)
file.close()
ui.setWindowFlags(Qt.Window)
ui.show()
def PiratePrint():
print "Haarrrrrr, this button be clicked!"
CreateUI()
The window shows up just fine. But what exactly do I need to do in QT Designer so that when the button is clicked, PiratePrint is called? From what I’ve found online, adding a Dynamic Property with “-command PiratePrint” to the button should work. But it doesn’t
Is there something else I need to do in the script to connect the button to the function?
Any help is appreciated, because so far I’ve found that manually coding my interfaces offers way more flexibility than using QT Designer UIs. But then again if I can get it working once, building UIs in QT Designer would definitely speed up my workflow.