Drag and Drop from QWidget to Maya MainWindow

383 views
Skip to first unread message

Arvid Schneider

unread,
Apr 4, 2016, 11:11:55 AM4/4/16
to Python Programming for Autodesk Maya
Hello, me again with Qt stuff..

So I have a QListWidget with lots of thumbnails of textures, hdrs, assets etc etc. 

I want to be able to drop this thumbnail into any QApplication ( for now Maya) and then I can call certain functions to create image nodes, lights, etc etc. 
I read about MimeData, and I read about eventFilter and install eventFilter. But I have no idea on how to get it to work, so Maya accepts drops and registers them. So I can call my functions.
Any help as always appreciated. 







Arvid

Marcus Ottosson

unread,
Apr 4, 2016, 1:19:58 PM4/4/16
to python_in...@googlegroups.com

Hey Arvid,

It sounds like you’ve got the gist of it. You’ll need to listen for both DragEnterEvent, to determine whether or not to accept the event, and DropEvent to decide what to do with it in case it gets accepted. Some widget will be more difficult to install such an event filter in than others; most prominently the main viewport. I’d probably try installing it onto the main application first, (PySide.QtGui.qApp) and go from there.

If you haven’t already had a look at this, I’d suggest taking a moment to read it through.


--
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/fd8bcc5a-7e01-4e03-bb55-e3ddf0d15c15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Arvid Schneider

unread,
Apr 5, 2016, 7:16:50 AM4/5/16
to Python Programming for Autodesk Maya
With some serious trial and error I found a solution which is actually quite straight forward, as its mostly the case...
So the main thing is to register the event with the main app in my case maya.

main_win = mhelper.getQMayaMainWindow()
main_win
.installEventFilter(drop_filter)  


and then in the event filter I need to check which event is being called:

def eventFilter(self, obj, event):
       
self.obj = obj      
       
       
if event.type() is event.DragEnter:
           
self.mouse_button = QtGui.QApplication.mouseButtons()
           
event.accept()
               
       
if event.type() is event.Drop:
            library_w
= event.source()
           
if self.mouse_button == QtCore.Qt.LeftButton:

           
....


and that is all of the magic..
Thanks Marcus and Justin






On Monday, April 4, 2016 at 6:19:58 PM UTC+1, Marcus Ottosson wrote:

Hey Arvid,

It sounds like you’ve got the gist of it. You’ll need to listen for both DragEnterEvent, to determine whether or not to accept the event, and DropEvent to decide what to do with it in case it gets accepted. Some widget will be more difficult to install such an event filter in than others; most prominently the main viewport. I’d probably try installing it onto the main application first, (PySide.QtGui.qApp) and go from there.

If you haven’t already had a look at this, I’d suggest taking a moment to read it through.

On 4 April 2016 at 16:11, Arvid Schneider <arvidsc...@gmail.com> wrote:
Hello, me again with Qt stuff..

So I have a QListWidget with lots of thumbnails of textures, hdrs, assets etc etc. 

I want to be able to drop this thumbnail into any QApplication ( for now Maya) and then I can call certain functions to create image nodes, lights, etc etc. 
I read about MimeData, and I read about eventFilter and install eventFilter. But I have no idea on how to get it to work, so Maya accepts drops and registers them. So I can call my functions.
Any help as always appreciated. 







Arvid

--
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+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Reply all
Reply to author
Forward
0 new messages