If you're interested in MVC in general, I just finished up on an example of implementing MVC in Python, using Qt and it's QEvent and pyqtSignal frameworks, a custom Controller and two custom Views.
Maybe it could be useful in your exploration. :) https://github.com/abstractfactory/labs/tree/master/python/mvc Best, Marcus On 13 June 2014 12:51, Marcus Ottosson <[email protected]> wrote: > Glad to hear you got it working. :) > > > On 13 June 2014 12:11, David Martinez <[email protected]> > wrote: > >> It's working now! Thanks a lot! >> >> Since I'm going through the proxy model, I had to use the 'mapToSource' >> method instead of the itemFromIndex. >> The final code looks like this: >> >> global_position = self.uiTree.mapToGlobal(pos) >> index = self.uiTree.indexAt(pos) >> proxyModel = self.uiTree.model() >> item = proxyModel.mapToSource(index) >> >> node = item.internalPointer() >> >> >> >> -- >> David Martinez - Technical Animator >> >> Email: [email protected] >> Website: http://www.elusiveideas.com >> >> >> >> >> On Fri, Jun 13, 2014 at 11:57 AM, Marcus Ottosson <[email protected] >> > wrote: >> >>> Looks like Erkan beat me to it. :) >>> >>> >>> On 13 June 2014 11:57, Marcus Ottosson <[email protected]> wrote: >>> >>>> The item you're getting is indeed from the proxy model. You'll have to >>>> get it, and then map it to the original. >>>> http://qt-project.org/doc/qt-4.8/qabstractproxymodel.html#mapToSource >>>> >>>> >>>> On 13 June 2014 11:40, David Martinez <[email protected]> >>>> wrote: >>>> >>>>> Hi, >>>>> >>>>> I've been experimenting with Model View Programming and so far, I've >>>>> been able to create a QTreeView which displays the data of my custom model >>>>> (Inheriting from 'QtCore.QAbstractItemModel'). I created my own custom >>>>> kind >>>>> of object to use within the model (as I'm storing some data about the >>>>> items >>>>> being stored). I use the 'internalPointer' method in the model to get a >>>>> reference to my original object if I need it. I also have a >>>>> 'QtGui.QSortFilterProxyModel' between the view and the model which allows >>>>> me to filter and sort the results. >>>>> >>>>> Everything seems to be working as expected but I'm struggling to get >>>>> something working. I want to be able to right click an item on the >>>>> treeView >>>>> and get a popup menu which contains information about the specific item. >>>>> >>>>> That means that I'm interested on the 'QModelI' value in the 'Model' >>>>> for the element selected in the 'QTreeView' so I can retrieve the original >>>>> node using 'internalPointer' and get the information that I need. >>>>> >>>>> I'm not sure how to get the index in the original 'model' though. I >>>>> have tried to use the 'indexAt(QPos)' method of the treeView but I guess >>>>> that this is returning the index that it has within the view and not the >>>>> model. >>>>> >>>>> I'm not sure if I would need something like a 'selectionModel'. I >>>>> started to try that but I think that it would give me the index of the >>>>> 'QSortFilterProxyMode' instead of the one of 'QAbstractItemModel'. >>>>> >>>>> Is there anything obvious that I'm missing? >>>>> >>>>> >>>>> Thanks in advance, >>>>> >>>>> >>>>> >>>>> -- >>>>> David Martinez - Technical Animator >>>>> >>>>> Email: [email protected] >>>>> Website: http://www.elusiveideas.com >>>>> >>>>> >>>>> -- >>>>> 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 [email protected]. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpwXVJS7Ko5_XUf3cTRML%2BpXBjt8h1Pm2EXz03HQaobR3Q%40mail.gmail.com >>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpwXVJS7Ko5_XUf3cTRML%2BpXBjt8h1Pm2EXz03HQaobR3Q%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> >>>> >>>> -- >>>> *Marcus Ottosson* >>>> [email protected] >>>> >>> >>> >>> >>> -- >>> *Marcus Ottosson* >>> [email protected] >>> >>> -- >>> 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 [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBL-ctm%3DZORqzDk%2B0L4tJmfDr_D7yQ4E-U%3DWVdePWMGqA%40mail.gmail.com >>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBL-ctm%3DZORqzDk%2B0L4tJmfDr_D7yQ4E-U%3DWVdePWMGqA%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >>> 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 [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpy7kocGrZXRSNhYfqUASVTwnHzm6FZmAQK4TLpUyrL66g%40mail.gmail.com >> <https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpy7kocGrZXRSNhYfqUASVTwnHzm6FZmAQK4TLpUyrL66g%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > *Marcus Ottosson* > [email protected] > -- *Marcus Ottosson* [email protected] -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCnUwWP3oSHxPQiWcOVH0e40iJxU%3D5dpSK%2BNWzWrG2L%2BQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
