Use:
global_position = treeView.mapToGlobal(position)
index = treeView.indexAt(position)
model = treeView.model()
item = model.itemFromIndex(index)
Ozgur
eoyilmaz.blogspot.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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpwXVJS7Ko5_XUf3cTRML%2BpXBjt8h1Pm2EXz03HQaobR3Q%40mail.gmail.com.
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpwXVJS7Ko5_XUf3cTRML%2BpXBjt8h1Pm2EXz03HQaobR3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpy7kocGrZXRSNhYfqUASVTwnHzm6FZmAQK4TLpUyrL66g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCnUwWP3oSHxPQiWcOVH0e40iJxU%3D5dpSK%2BNWzWrG2L%2BQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpwCw1k5xqx1cMY_bitayYF74DJr%3D-%2BarDebKriq3Mg6ZQ%40mail.gmail.com.
Thanks a lot for sharing this, it is a great source and a great example to the tons of things that I've to learn from you guys.
Ozgur
eoyilmaz.blogspot.com
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCz3jDmqvV4kGYJ01XCFxVyA-edh-3ibT8rGWxNPAB%2BQA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAGNmyx7tt8rDLDEQUEEYR2dBC0-RwpDd0JeUiCxJufHEkJv8Cg%40mail.gmail.com.
Hey David,
I wanted to add that you should not use the internalPointer method outside of the internal code of your model. Normally in Qt land that would return a pointer to something outside components shouldn't be messing with but I know it feels natural to use it when you are setting your own objects. Probably better to write an abstraction around that as a method on your model.
What I tend to do is create custom role types and serve stuff through the data() method.
Something like:
# class attribute on model
ObjectRole = QtCore.Qt.UserRole+1
...
def data(index, role):
if role == self.ObjectRole:
# resolve and return the object
....
That way you are covered if your model stores it's objects in a private list or dict or internalPointer.
Something to keep an eye out for... I just recently had to fix a tricky bug where randomly my model would crash saying that various attributes didn't exist on a custom item I store in my model, when they are part of the subclass implementation. Turned out that using internalPointer as the only place to store your object can lead to garbage collection issues and corruption. It would return broken instances of my items. I found similar reports of this online. Solution was to store my own mapping of the objects as well and manage adding and removing them properly, and then storing only a unique id as the internalPointer to look them up.
Thus was only one specific model that had this problem, as other models in my app were purely using internal lists and no internalPointer calls.
Also Erkan, I think your answer was meant for a QTreeWidget where you are dealing with converting between indexes and model items.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCH1aLNoYNh%2BTkd4EYu6RVg6v9r6Sc1%3DhsP-K_AGeiuZQ%40mail.gmail.com.
On Jun 14, 2014 8:17 AM, "Justin Israel" <justin...@gmail.com> wrote:
>
> Also Erkan, I think your answer was meant for a QTreeWidget where you are dealing with converting between indexes and model items.
>
Correction. I should have said a QTreeView in combination with QStandardItemModel subclasses where it deals with items in the model. QAbstractItemModel is index like the view.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0dNpOefm%3DLppQNrKrHPki-yOxifFM30jmKeq34NVn59Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpwpDT_mKd-3R1yzBhHeckvrY9DDdwq4-DJGXcvPto0kMw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0B0x6CiLFR0XFr_UmkmdanSGA2Wcy_Z0iRirAiC70rfw%40mail.gmail.com.