[Maya-Python] mousePressEvent for swatchDisplayPort

115 views
Skip to first unread message

Risto Jankkila

unread,
Jun 5, 2014, 5:49:32 AM6/5/14
to python_in...@googlegroups.com
Hi,

I'm trying to execute a function when user clicks a swatchDisplayPort that's inside a Qt-window.

Currently my code looks something like this:

swatch_name = cmds.swatchDisplayPort(rs=64, wh=[64, 64], sn="lambert1")
ptr = OpenMayaUI.MQtUtil.findControl(swatch_name)
swatch_widget = shiboken.wrapInstance(long(ptr), QtGui.QWidget)
swatch_widget.mousePressEvent = my_func

I can get this to work on other Qt-objects (ie. labels) but not with swatchDisplayPorts.
Any help would be greatly appreciated.

Cheers,
Risto

Marcus Ottosson

unread,
Jun 5, 2014, 9:48:14 AM6/5/14
to python_in...@googlegroups.com
Hi Risto,

What is "my_func"?


--
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/CA%2B5uDBZ2J8vPY%3Do6i3MgsZz5u_GzUwM3T4jU0wYAS5zehhMk9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



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

Risto Jankkila

unread,
Jun 5, 2014, 11:39:23 AM6/5/14
to python_in...@googlegroups.com
Hi Marcus,

"my_func" would be any function I would like to use to override mousePressEvent-method.

My colleague pointed out that event filters are a better way of doing this sort of thing, but I still wonder why this doesn't work with swatchDisplayPorts.

Cheers,
Risto



For more options, visit https://groups.google.com/d/optout.



--
-------------------------------------------
Risto Jankkila
mob. +44 (0)77 6741 9890 (UK)
mob. +358 (0)40 5422 625 (FI)
ristoj...@gmail.com
-------------------------------------------

Marcus Ottosson

unread,
Jun 5, 2014, 11:43:53 AM6/5/14
to python_in...@googlegroups.com
It may be that there are widgets on top of the widget you are monkey-patching that intercepts and accepts press events before it reaches your custom function.



For more options, visit https://groups.google.com/d/optout.



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

Risto Jankkila

unread,
Jun 5, 2014, 1:37:15 PM6/5/14
to python_in...@googlegroups.com
You're probably right. Also shows why it was such a bad idea in the first place.

Thanks Marcus.




For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Jun 5, 2014, 1:49:35 PM6/5/14
to python_in...@googlegroups.com
You can try running a QWidget.childAt(x, y) on the top-level widget to find out which widget will be receiving your mousePress'es first. That's the one you want to monkey-patch.



For more options, visit https://groups.google.com/d/optout.



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

Marcus Ottosson

unread,
Jun 5, 2014, 1:50:04 PM6/5/14
to python_in...@googlegroups.com
*There are exceptions to this, but it might give you a place to start.
--
Marcus Ottosson
konstr...@gmail.com

Reply all
Reply to author
Forward
0 new messages