PyQt6 Mouse Hover event over QPushButtons in a gridlayout

551 Views Asked by At

I'm trying to connect Mouse Hover Event and QPushButtons. I want to change CheckStatus on the next when I hover over it after I pressed on one of the button.

enter image description here

I was able to connect this event with the buttons. But I can't understand how to connect it with press button event.

def __init__(self):
    super().__init__()
    uic.loadUi("my_file.ui", self)

    self.gridLayout.installEventFilter(self)

    for button in self.gridLayoutWidget.findChildren(QtWidgets.QAbstractButton):
        button.clicked.connect(self.rangeButtonClicked)
        button.setAttribute(Qt.WidgetAttribute.WA_Hover)
        button.installEventFilter(self)

    self.gridLayout.installEventFilter(self)

def eventFilter(self, obj, event):
    if event.type() == QEvent.Type.HoverEnter:
        sender = obj
        sender.nextCheckState()

    return super().eventFilter(obj, event)

Required actions:

  1. I press the button
  2. I move the mouse along the rest of the buttons
  3. The pressed button and those over which the mouse hover - change the status
0

There are 0 best solutions below