Creating a QApplication is only something you would want to do for a
standalone application. Maya is already a Qt application and already has an
instance of one. There can only be one and its a shared global instance.
It would be better to make use of "if main" for this:
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
You definitely do not want that stuff in the constructor of your class,
because it needs to happen in your main, only once. Not for every instance
you create. Same goes for setting the style.
A concept you are missing here in your example is the idea of parent-child
relationships between widgets. What you have in your dialog is that the
constructor creates a list widget, with no parent, and shows it. This would
end up creating two independent widgets. What you want is to either set
the parent for that list widget, or add it to a layout:
self._listWidget = QtGui.QListWidget(self)
layout = QtGui.QVBoxLayout(self)
On Tue, Sep 20, 2016 at 10:40 AM likage <dissidia....@gmail.com> wrote:
> 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()
> class BasicDialog(QtGui.QDialog):
> def __init__(self, parent=getMayaWindow()):
> super(BasicDialog, self).__init__(parent)
> #app = QtGui.QApplication(sys.argv)
> # 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:
> # Model
> model = QtGui.QStringListModel(data)
> listView = QtGui.QListView()
> 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
> For more options, visit https://groups.google.com/d/optout.
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 view this discussion on the web visit
For more options, visit https://groups.google.com/d/optout.