Dec-01-2019, 08:15 AM
Hi,
I'm working on a project where I need to change the painting of a widget when the mouse is hovering over it. The issue I'm having is I can't get the leave event to trigger for a widget when the mouse hovers over one of its children.
![[Image: 4wM4P1T.png]](https://i.imgur.com/4wM4P1T.png)
So here, when the mouse enters
I've also tried installing an eventFilter and using HoverLeave and HoverEnter, with the WA_Hover attribute set, however this gives me the same behavior.
Minimal Example:
I'm working on a project where I need to change the painting of a widget when the mouse is hovering over it. The issue I'm having is I can't get the leave event to trigger for a widget when the mouse hovers over one of its children.
![[Image: 4wM4P1T.png]](https://i.imgur.com/4wM4P1T.png)
So here, when the mouse enters
One
, I want it's enterEvent to be triggered, however when the mouse enters Two
I want One
to have its leaveEvent triggered. Keep in mind this could be a complicated nest of layouts and widgets that can be dragged and dropped.I've also tried installing an eventFilter and using HoverLeave and HoverEnter, with the WA_Hover attribute set, however this gives me the same behavior.
Minimal Example:
import sys from PyQt5 import QtWidgets class TestWindow(QtWidgets.QDialog): def __init__(self, parent=None): super(TestWindow, self).__init__(parent=parent) self.resize(640, 480) layout = QtWidgets.QVBoxLayout() self.setLayout(layout) widget1 = CustomWidget("One") widget2 = CustomWidget("Two") widget1.layout().addWidget(widget2) layout.addWidget(widget1) class CustomWidget(QtWidgets.QFrame): def __init__(self, name, parent=None): super(CustomWidget, self).__init__(parent=parent) self.setObjectName(name) self.setFrameStyle(QtWidgets.QFrame.StyledPanel) self.setLayout(QtWidgets.QVBoxLayout()) self.layout().addWidget(QtWidgets.QLabel(name, parent=self)) def enterEvent(self, event): print("Enter:", self.objectName()) def leaveEvent(self, event): print("Leave:", self.objectName()) if __name__ == "__main__": qApp = QtWidgets.QApplication(sys.argv) tw = TestWindow() tw.show() sys.exit(qApp.exec_())Thanks for the help!