Discussion:
[Maya-Python] QPushButton hover
o***@gmail.com
2018-08-20 00:01:31 UTC
Permalink
Hello. I have been trying to find a way to run a function when the mouse is on top of a button. I tried to overrride the QPushButton class, and the enterEvent function, but I dont have any results. This is what I have:

class CustomButtom(QtGui.QPushButton):

def __init__(self):
pass

def mouseMoveEvent(self, event):
print("in focus")

def enterEvent(self, event):
print("Enter")

def leaveEvent(self, event):
print("Leave")

I have an extra function to create the buttons, and in there I set the setMouseTracking(1) to 1.

What am I missing?. My guess is that I need to connect the enter and and leave event, but, to who?I thought they would be connected to the mouse movement already.

Thanks.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/693291aa-7811-42ad-8660-3e51b25ebe3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-08-20 01:41:30 UTC
Permalink
Post by o***@gmail.com
Hello. I have been trying to find a way to run a function when the mouse
is on top of a button. I tried to overrride the QPushButton class, and the
pass
You broke the constructor by overriding it and not calling the parent
constructor. Either remove this, or do:

super(CustomButtom, self).__init__()
Post by o***@gmail.com
print("in focus")
print("Enter")
print("Leave")
I have an extra function to create the buttons, and in there I set the
setMouseTracking(1) to 1.
What am I missing?. My guess is that I need to connect the enter and and
leave event, but, to who?I thought they would be connected to the mouse
movement already.
Thanks.
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/693291aa-7811-42ad-8660-3e51b25ebe3c%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0EqWmh-v4T-BUfi7xLpwMv%2BzZ3xo_DwFT3ZMyBH1WBVQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
o***@gmail.com
2018-08-20 02:04:33 UTC
Permalink
Hi Justin. Thanks for taking some time to answer me. I tried removing it and also re-working the constructor, but I still have no results when my cursor hovers on top of the button:

https://pastebin.ubuntu.com/p/GtMq6qDZZ9/

thanks
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d3b8286d-39f9-4ad0-9f3d-3d72bfd7ea3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-08-20 02:25:10 UTC
Permalink
Can you show me a complete example of how you are using the button in
combination with your app? When I test your code, the enter/exit logic
still fires. Although with your constructor, I can't pass it a parent or
text directly.
Post by o***@gmail.com
Hi Justin. Thanks for taking some time to answer me. I tried removing it
and also re-working the constructor, but I still have no results when my
https://pastebin.ubuntu.com/p/GtMq6qDZZ9/
thanks
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/d3b8286d-39f9-4ad0-9f3d-3d72bfd7ea3f%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0VOHqRiiZiyxRsC%2Bh54c5vaw%3DRi0x0RJ87mfepbkumbw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
o***@gmail.com
2018-08-20 02:34:14 UTC
Permalink
I can send you the whole code to your email, yes.

Sorry, what do you mean with my constructor?how would be the correct way?
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7ab15662-cd0a-41b6-80c8-c599223ecbf6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
o***@gmail.com
2018-08-20 02:40:03 UTC
Permalink
here is the code:

https://pastebin.com/tii0rR1M

thanks again.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c1fd2da1-c565-44a4-88f7-eeabee24317b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-08-20 11:14:45 UTC
Permalink
Post by o***@gmail.com
https://pastebin.com/tii0rR1M
thanks again.
Ok now I see your problem. Thanks for providing a more complete example.
You have defined your custom event logic on your CustomButtom class, but
then you have your createWindowsFunction() create a local instance which
you don't save, and then you call buttonCreator() which creates a
completely generic button parented to the Maya main window. That function
doesn't return anything so you just end up setting self.windowNorthButton
to None. Then you let your local CustomButtom go unsaved and get garbage
collected.
I actually don't even know how this code works correctly but I will only
focus on your original question. You aren't operating on your CustomButtom
logic. You just use it to create another generic QPushButton. So the
solution is to create and save an instance of your custom class instead.

What I meant about your __init__() is that in its current state it isn't
helping you and actually making your CustomButtom less useful by not
letting you do CustomButtom("text", main Window). Better to just remove it
entirely if it isn't going to do anything useful.
Post by o***@gmail.com
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/c1fd2da1-c565-44a4-88f7-eeabee24317b%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2tywvG4xg4Vg65Bwf%2B6Vq1iZukOu7EQBEnr_3tTAn%2B%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Marcus Ottosson
2018-08-20 11:42:18 UTC
Permalink
but I still have no results when my cursor hovers on top of the button:

This works for me.

from PySide import QtGui
class CustomButtom(QtGui.QPushButton):
def enterEvent(self, event):
print("Enter")

def leaveEvent(self, event):
print("Leave")

button = CustomButton()
button.show()# Enter# Leave
Post by Justin Israel
Post by o***@gmail.com
https://pastebin.com/tii0rR1M
thanks again.
Ok now I see your problem. Thanks for providing a more complete example.
You have defined your custom event logic on your CustomButtom class, but
then you have your createWindowsFunction() create a local instance which
you don't save, and then you call buttonCreator() which creates a
completely generic button parented to the Maya main window. That function
doesn't return anything so you just end up setting self.windowNorthButton
to None. Then you let your local CustomButtom go unsaved and get garbage
collected.
I actually don't even know how this code works correctly but I will only
focus on your original question. You aren't operating on your CustomButtom
logic. You just use it to create another generic QPushButton. So the
solution is to create and save an instance of your custom class instead.
What I meant about your __init__() is that in its current state it isn't
helping you and actually making your CustomButtom less useful by not
letting you do CustomButtom("text", main Window). Better to just remove it
entirely if it isn't going to do anything useful.
Post by o***@gmail.com
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/c1fd2da1-c565-44a4-88f7-eeabee24317b%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2tywvG4xg4Vg65Bwf%2B6Vq1iZukOu7EQBEnr_3tTAn%2B%3DQ%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2tywvG4xg4Vg65Bwf%2B6Vq1iZukOu7EQBEnr_3tTAn%2B%3DQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB%2B0Ux7U%2Bq3yHY1BVsRHM2meSb0WNNfS-xL8KEuATwVXg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
o***@gmail.com
2018-08-20 19:50:27 UTC
Permalink
@Marcus
Hello Marcus. Thanks for taking some time to answer back.

Yes, this should work with me too, but looks like the problem I have is that I am calling my customButtom class from inside another class, then, when I call the whole thing in maya, it gets garbage collected.

Osmel.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/55cf6175-c697-4e88-a785-63bbbcc2e636%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
o***@gmail.com
2018-08-20 19:38:45 UTC
Permalink
Hi Justin. I have 2 questions tho. You mention that I am operating in my custom CustomButtom logic, but when I create a button, I have the text from that custom class. If it`s picking up the default QPushButton class, why I have the text?I think I`m confused about this.

The second thing is that you say create and save. My guess is that I need to create an instance from the CustomButtom class, and return it, which is something I am not doing right now. Is that it?

thanks again for your time, it would take me some time to figure it out by myself.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/8bcc6aca-04b6-4fef-93b9-8df019f1baba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-08-20 19:55:31 UTC
Permalink
Post by o***@gmail.com
Hi Justin. I have 2 questions tho. You mention that I am operating in my
custom CustomButtom logic, but when I create a button, I have the text from
that custom class. If it`s picking up the default QPushButton class, why I
have the text?I think I`m confused about this.
First look at this code when you create the button :

buttonCreatorInstance = CustomButtom()
self.windowNorth = self.menuLikeWindow("windowNorth")
self.windowNorthButton =
buttonCreatorInstance.buttonCreator(self.windowNorth, "buttonWindNorth",
self.windowsList)

Your custom button is created locally with no text and no parent. It will
die after this function ends.
You call the creator method on it, passing a parent and text. And save None
as the result to your windowNorthButton field.

Now look at how the button is created:

def buttonCreator(self, parentWindow, buttonName, windowsList):
self.buttonTest = QtGui.QPushButton(parent = parentWindow)
self.buttonTest.setObjectName(buttonName)
self.buttonTest.setText("test")

You create your button with just the parent. You set the object name to the
text, which isn't a display property. And then you set the text to a hard
coded literal.
Post by o***@gmail.com
The second thing is that you say create and save. My guess is that I need
to create an instance from the CustomButtom class, and return it, which is
something I am not doing right now. Is that it?
Yes. Instead of that creator method creating a QPushButton, just have it
create a CustomButtom, and also don't make it a method of CustomButtom.
Honestly, it feels like all of that creator code should be in your
CustomButtom.__init__
Post by o***@gmail.com
thanks again for your time, it would take me some time to figure it out by myself.
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/8bcc6aca-04b6-4fef-93b9-8df019f1baba%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2B0V_rRV8%2BkQ7y3%3DZ%3D-7xXcNcm1GxkFmuUhg4d3vJDhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
o***@gmail.com
2018-08-20 20:11:29 UTC
Permalink
all right. As soon as I get home I`m gonna go line by line with this answer to fix it. Im trying to practice every night, when possible.

Thanks.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/362bbba5-16c8-459c-9106-0c7ba1894800%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
o***@gmail.com
2018-08-24 05:58:48 UTC
Permalink
Hi. This is how I fix it, thanks to you guys. I dont know why I was creating a function for the button:

class CustomButtom(QtGui.QPushButton):
def __init__(self, parentWindow, buttonName, windowsList, icon):
super(CustomButtom, self).__init__(parentWindow)

#self.icon = QtGui.QIcon(":/clusterHandle.svg")
QtIcon = QtGui.QIcon(icon)
self.setParent = parentWindow
self.setObjectName(buttonName)
self.setGeometry(QtCore.QRect(0, 0, 50, 50))
self.setIcon(QtIcon)
self.setIconSize(QSize(45, 45))
self.clicked.connect(partial(self.closeWindow, windowsList))
self.setMouseTracking(1)
self.setStyleSheet("border: none;")

thanks again
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4864dffa-cb76-4150-b53f-d37cd9dacb52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-08-24 07:17:13 UTC
Permalink
One thing...
This is a bug:

self.setParent = parentWindow

You replace the actual setParent() method on your button which might cause
confusing errors later. There isn't a reason to save that parent since you
can query it any time with self.parent()
Post by o***@gmail.com
Hi. This is how I fix it, thanks to you guys. I dont know why I was
super(CustomButtom, self).__init__(parentWindow)
#self.icon = QtGui.QIcon(":/clusterHandle.svg")
QtIcon = QtGui.QIcon(icon)
self.setParent = parentWindow
self.setObjectName(buttonName)
self.setGeometry(QtCore.QRect(0, 0, 50, 50))
self.setIcon(QtIcon)
self.setIconSize(QSize(45, 45))
self.clicked.connect(partial(self.closeWindow, windowsList))
self.setMouseTracking(1)
self.setStyleSheet("border: none;")
thanks again
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/4864dffa-cb76-4150-b53f-d37cd9dacb52%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1F%2BX0i6b14bSUjXYnAiQ8w9sNzS%3DPS0wQhzYqGJQD65w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...