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.
Maya API: QT Mouse Hover
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)
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()
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!
Unwrap the PyQt sip object to it’s pointer. Then use MQtUtil fullName which takes a QObject pointer.
apiUI.MQtUtil.fullName( sip.unwrapinstance(widget) )
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 *’
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.