PDA

View Full Version : Maya API: QT Mouse Hover


migusan76
11-08-2010, 05:27 AM
Hi, I just wanted to share my code for a partial working mouse hover code using QT and maya. It was something I was working on and might not ever work on again, but would love to share it with anyone who might be on the same quest. It was originally intended for use with pre-selection highlighting type tool. So only at the moment the code grabs maya's viewport and passes it to qt to capture the mouse hover position. Hope it helps anyone looking.

nuttynut
11-08-2010, 10:22 AM
ha! Great, happy you got it to work! Thanks for sharing :beer:

NateH
11-08-2010, 04:44 PM
Neat idea! Thanks for sharing!

I went an implemented something similar using PyQt based somewhat off your example. I used the ToolTip event instead of MouseMove though, but it's easy to change it to use either:

import sip
import maya.cmds as cmds
import maya.OpenMayaUI as apiUI
from PyQt4 import QtGui, QtCore


class ToolTipFilter(QtCore.QObject):
'''A simple event filter to catch tooltip events'''
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.ToolTip:
QtGui.QToolTip.hideText() #Hide the old tooltip, so that it can move
QtGui.QToolTip.showText(event.globalPos(), '%04f, %04f'%(event.globalX(), event.globalY()), obj)
return False
return True


#Install the event filter into all the model panels
global filter #Have to make the filter object global so it doesnt get garbage collected
filter = ToolTipFilter()

for editor in cmds.lsUI(panels=True): #For soem reason type='modelEditor' won't work...
if cmds.objectTypeUI(editor)=='modelEditor':
ptr = apiUI.MQtUtil.findControl(editor)
viewWidget = sip.wrapinstance(long(ptr), QtCore.QObject)
viewWidget.installEventFilter(filter)

ginodauri
11-08-2010, 06:53 PM
One question:
Is it possible through qt to get control under pointer or control with focus?
Maya(mel,python) don't have this functionality , but this would very interesting to have.

NateH
11-08-2010, 07:10 PM
One question:
Is it possible through qt to get control under pointer or control with focus?
Maya(mel,python) don't have this functionality , but this would very interesting to have.

Yep, easy:
def getWidgetAtMouse():
currentPos = QtGui.QCursor().pos()
widget = QtGui.qApp.widgetAt(currentPos)
return widget

def getFocusWidget():
return QtGui.qApp.focusWidget()

migusan76
11-08-2010, 08:08 PM
Hey Waldo, Yea finally got it to work. Thx's for the suggestion on it! It wasn't very hard once I learned a little on Qt. Its a good start to get the hover, but so much more to do to get some kind of pre-selection tool going. I just remeber the couple of weeks of hell I went through trying to do something so simple, that hopefully this helps out anyone on the same path. :banghead:

Awesome stuff Nate, thx's for sharing as well! :)

ginodauri
11-08-2010, 08:16 PM
Nice

But how to convert qtObjects in maya "string" representation?

NateH
11-08-2010, 08:22 PM
Nice

But how to convert qtObjects in maya "string" representation?

Unwrap the PyQt sip object to it's pointer. Then use MQtUtil fullName which takes a QObject pointer.

apiUI.MQtUtil.fullName( sip.unwrapinstance(widget) )

ginodauri
11-08-2010, 08:50 PM
For some reason this isn't working , i get error

# Error: TypeError: file <maya console> line 1: in method 'MQtUtil_fullName', argument 1 of type 'QObject const *' #

CGTalk Moderation
11-08-2010, 08:50 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.