Hi all, I have just started learning on pyqt4 model/view and I had thought 
of trying out a very simple code to populate maya items into a QListView. 
As I run the following code in an editor (without those maya 
modules/lines), I am able to see QListView being called and populated with 
the information.

As soon as I tried running the code in Maya, the session keeps crashing on 
me unless I comment out the lines on 'app' and 'sys.exit'
But even so, if those lines are commented out, while it does pops up a 
window, nothing was populated within.

Can someone kindly advise?

# PyQt4 Modules
from PyQt4 import QtGui, QtCore, uic
import sip
import sys
import maya.cmds as cmds
import maya.OpenMayaUI as mui

def getMayaWindow():
    ptr = mui.MQtUtil.mainWindow()
    return sip.wrapinstance(long(ptr), QtCore.QObject)

def main():
    dialog = BasicDialog()
    dialog.show()
    
    
class BasicDialog(QtGui.QDialog):
    def __init__(self, parent=getMayaWindow()):
        super(BasicDialog, self).__init__(parent)
        #app = QtGui.QApplication(sys.argv)
        #app.setStyle("cleanLooks")
    
        # Data
        data = QtCore.QStringList()     
        #data << "one" << "two" << "three" << "four" << "five"   
        
        geos = cmds.ls(type = "mesh")
        sel = cmds.listRelatives(geos, parent = True)
        for item in sel:
            data.append(QtCore.QString(str(item)))
        
        # Model
        model = QtGui.QStringListModel(data)
        
        listView = QtGui.QListView()
        listView.show()
        listView.setModel(model)
        
        #sys.exit(app.exec_())
main()


-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/b37a7724-68d9-4ae8-811f-0d7233b7daf7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to