Maya API: QT Mouse Hover

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 11 November 2010   #1
Maya API: QT Mouse Hover

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.
Attached Files
File Type: zip mouseHoverQT.zip (7.3 KB, 355 views)
__________________
DigiTecK3D - LinkedIn - Facebook - Twitter
 
Old 11 November 2010   #2
ha! Great, happy you got it to work! Thanks for sharing
 
Old 11 November 2010   #3
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:

Code:
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)
__________________
www.nathanhorne.com - Technical Artist

Last edited by NateH : 11 November 2010 at 05:56 PM.
 
Old 11 November 2010   #4
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.
 
Old 11 November 2010   #5
Quote:
Originally Posted by ginodauri
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:
Code:
def getWidgetAtMouse(): currentPos = QtGui.QCursor().pos() widget = QtGui.qApp.widgetAt(currentPos) return widget


Code:
def getFocusWidget(): return QtGui.qApp.focusWidget()
__________________
www.nathanhorne.com - Technical Artist
 
Old 11 November 2010   #6
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.

Awesome stuff Nate, thx's for sharing as well!
__________________
DigiTecK3D - LinkedIn - Facebook - Twitter
 
Old 11 November 2010   #7
Nice

But how to convert qtObjects in maya "string" representation?
 
Old 11 November 2010   #8
Quote:
Originally Posted by ginodauri
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.

Code:
apiUI.MQtUtil.fullName( sip.unwrapinstance(widget) )
__________________
www.nathanhorne.com - Technical Artist
 
Old 11 November 2010   #9
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 *' #
 
Old 11 November 2010   #10
Thread automatically closed

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.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:33 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.