Saturday, March 17, 2012

[Maya] Handle MouseMove Event

Maya doesn't have MouseMove event, only provide doPress, doDrag and doRelease. One way to deal with MouseHover would be using Qt which is available since Maya 2011.

We can get QWidget from Maya's M3dView, then use it to instantiate a QWidget object with EventFilter installed and MouseTracking enabled. With eventFilter method, MouseMove event can be detected.

Quite straightforward and good so far. However, here is the thing.
For some reasons, if I just passed my M3dView to QWidget, that M3dView would only be valid at that moment. When it gets into the eventFilter method, it wouldn't be valid anymore. But I need that view to handle the scene in Maya.

There is an alternative. Within eventFilter method, I can get the name of the model panel I'm working on in Maya (via watchedObject->objectName()). Given the name of the model panel, M3dView::getM3dViewFromModelPanel should return the valid M3dView. Then I can do what I want to do with Maya scene under MouseMove event captured in Qt.

Interesting huh...

2 comments:

  1. Hi,

    I am learning Qt for Maya using c++. Writing my own brush, but stuck at tracking mouse cursor.

    And this made me more Confusing:
    "If you were writing your own Qt application from scratch, you would need to create your own QCoreApplication or QApplication instance to handle your application's event loop. When writing a Maya plug-in, you must instead use Maya's own application object which can be retrieved using Qt's qApp macro. The example code below uses the qApp macro to retrieve Maya's application name"

    It would be helpful if you can just provide a small help regarding how to do this

    Thanks
    Tushar

    ReplyDelete
  2. Hello Tushar, I'm sorry i didn't notice your comment until now. I know it's been QUITE a while. Just want to know whether you have already solved your problem?

    ReplyDelete