I guess we all have to start somewhere but I’m struggling to get my head round using QT Designer and Pymel.
I’ve created a simple .ui file using designer (see attached) and can load it in Maya using Nathan’s piece of code on his site. (great job btw!) I can see how this can be very useful to quickly get a GUI going. The problem is how do I access the various parts in Maya.
I’ve gone through the Pymel help and can see how I would create something similar like
But how would I say reference the textScrollList object if it’s come from the .ui. Or how would I set a script to run if the “Select” button was clicked.
Is there any help or tutorials on using QT in Maya a bit like there is for Pymel.
I did some testing at work before summer vacation to see if we should start using QtDesigner as standard but right now we decided not to as there are still communication issues between the interface and the scripts in our opinion.
Here is a list of communication paths I compiled when looking at which maya.cmds python command could communicate with which interface object. It started of based on the one found in the tutorial above.
Window (window) -> mc.window(“TestWindow”, q=True, ex=True)
Menu Bar (menu) -> COULD NOT GET WORKING
Most of the QT UI’s i have done have been dynamic to the point where designer is redundant, but i have done a little bit of stuff through designer. Generally ( out of habbit more than anything else ) i tend to hook up the signals through code after loading the ui file in, and have hit no issues using that approach.
If you want any examples of that just drop me a pm and i’ll send some over.
maybe this will help a little, copy this into a .py file and place the .ui file in the same dir, then import it into the maya script editor and call the example() method.
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.uic import *
import sip
import maya.OpenMayaUI as mui
import os
import pymel.core as pm
ui_file = os.path.dirname(__file__) +"\\demo.ui"
class MyWidget(QWidget):
def __init__(self , parent=None):
QWidget.__init__(self, parent=parent)
## Create main layout, and load the UI file
self.primary_layout = QVBoxLayout()
self.ui = loadUi(ui_file)
## Add the UI elements to the widget
self.primary_layout.addWidget(self.ui)
self.setLayout(self.primary_layout)
## Hook up the signals to the methods below
self.connect(self.ui.SelectButton, SIGNAL('clicked()'), self.clickedSelect)
self.connect(self.ui.SelectionBox, SIGNAL('itemSelectionChanged()'), self.selectionChanged)
## Method which is triggered on the button click
def clickedSelect(self):
print "I have just clicked select"
pm.polySphere()
## Method which is triggered on list box selection change
def selectionChanged(self):
print "selection changed"
print self.ui.SelectionBox.currentItem().text()
##----------------------------------------------------------------------------------------------
def getMayaWindow():
#Get the maya main window as a QMainWindow instance
ptr = mui.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QObject)
##----------------------------------------------------------------------------------------------
class MyWindow(QMainWindow):
'My custom window, which i want to parent to the maya main window'
def __init__(self, parent=getMayaWindow()):
#Init my main window, and pass in the maya main window as it's parent
QMainWindow.__init__(self, parent)
self.widget = MyWidget()
self.setCentralWidget(self.widget)
self.setWindowTitle("MyWindow")
self.resize(285,350)
def example():
window = MyWindow()
window.show()
Not sure if that helps at all, its been a long day so i hope i have not completely miss-read your question!
[QUOTE=Wolfsong;11491]
Combo Box (optionMenu) -> COULD NOT GET WORKING
[/QUOTE]
Hey Erik,
I’ve been using qComboBoxes as optionMenus without any problems. I guess the only thing is to make sure you’re using the “list based” rather than the “model based” version of the combo box.
as for menubars, i’ve had to leave some room at the top of my layout with a spacer, and then add in a menubar with maya.cmds - pretty fugly, but it’s working.
I’ve been using qComboBoxes as optionMenus without any problems. I guess the only thing is to make sure you’re using the “list based” rather than the “model based” version of the combo box.
as for menubars, i’ve had to leave some room at the top of my layout with a spacer, and then add in a menubar with maya.cmds - pretty fugly, but it’s working.
cheers,
chrisg[/QUOTE]
The only other Combo Box in Qt Designer I can see is Font Combo Box.
I’m running Maya 2012 and the Qt Designer that came with it btw.
Thanks, it works fine. Don’t know what I did wrong when I tested, but didn’t put much time into it.
Still, like Mike said, most interfaces are dynamic so we can’t use Designer for it anyways. And as we only use what ships with Maya, so it’s easier and faster to build interfaces with PyMEL or maya.cmds.
Anyhow, updated for referense:
Window (window) -> mc.window(‘TestWindow’, q=True, ex=True)
Menu Bar (menu) -> COULD NOT GET WORKING
Great stuff. Thanks Eric, Mike and Chris. Some great Monday morning reading for me to get into. When you say the UI id dynamic do you mean dynamic in the way it handles objects (nulls, cameras etc) or dynamic in the way it’s built (multiple floating windows etc)
I’m going to go through the tutorial and this should hopefully give me a clearer picture of what I want to do and how I go about achieving it.
Dynamic as in created by code on the fly depending on what data it is given or what options the user has made.
I guess we could do a lot of smaller parts in our interface with ui files, but when you’re used to creating them by code you get a template to follow and then it’s quite quick.
It probably great for new users though as it’s much easier to create more complexed layouts and such this way then when I tried to learn it back in Maya 7 with MEL.
You can also do a hybrid approach for dynamic UIs - you can create a basic layout in Designer for the things that don’t change, and leave blank (and named) layout elements that you can later populate on the fly. I’ve done this a few times, and it works reasonably well.