为什么单击QToolButton会生成leaveEvent?有解决办法吗?

为什么单击QToolButton会生成leaveEvent?有解决办法吗?,qt,Qt,出于某种原因,每当单击QToolButton的菜单按钮部分时,它都会生成一个短暂的leaveEvent(至少当它位于工具栏中时)。我甚至在leaveEvent中测试了underMouse(),结果返回false。为什么会这样?有办法解决这个问题吗 测试样本(Py3.3,将super()更改为py2.7): 以下可用于双重检查;与leaveEvent不同,它始终返回正确的信息: def leaveEvent(self, event): if not QApplication.widgetA

出于某种原因,每当单击QToolButton的菜单按钮部分时,它都会生成一个短暂的leaveEvent(至少当它位于工具栏中时)。我甚至在leaveEvent中测试了underMouse(),结果返回false。为什么会这样?有办法解决这个问题吗

测试样本(Py3.3,将super()更改为py2.7):


以下可用于双重检查;与leaveEvent不同,它始终返回正确的信息:

def leaveEvent(self, event):
    if not QApplication.widgetAt(QCursor().pos()) is self:
        #do stuff
    super().leaveEvent(event)

这对我来说似乎很管用。当我点击菜单按钮时,离开事件不会发生:它只在我将鼠标移动到菜单时发生:它对你有不同的作用吗?我不太明白为什么你会认为这是一个问题。尝试列出
事件的内容
,看看有什么。也许你可以根据它来区分。@PavelStrakhov:对我不起作用。也许是这个版本?我正在使用PyQt 4.10.1qt4.8.4x64和Py3.3.1x64Win7@KubaOber:我需要根据鼠标是否在ToolButton上更改ToolButton绘制/样式。当前,每次单击它时,两个版本之间都会出现一个闪烁。同样,当调用您不想要的
leaveEvent
时,
event
的内容是什么?
def leaveEvent(self, event):
    if not QApplication.widgetAt(QCursor().pos()) is self:
        #do stuff
    super().leaveEvent(event)