Handling touch events for parent and child widgets
Hello!
There are two widgets - parent (main window) and child (pop-up menu):
Code:
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
def __init__(self):
self.menu = Menu(parent=self)
self.menu.hide()
...
def __init__(self, parent):
...
By default, menu is hidden. The menu should be shown when touch on the main window area. This task is easily solved with QEvent.TouchBegin:
Code:
def eventFilter(self, obj, event):
if event.
type() == QEvent.
TouchBegin: self.
menu.
show()
The menu should become hidden when touch on any area of the main window that doesn't have a menu above it (a touch outside the menu).
Is there an easy way to detect this event (without using touch coordinates)?
Re: Handling touch events for parent and child widgets
I am not sure why you are using an event filter when all you really need to do is override the QWidget::event() method in your main window class to look for TouchBegin events. When you detect a touch, if the menu is not visible, you show it, if it is visible, you hide it. The menu itself will handle its own touch events and will hide itself when an action is triggered.
Event filters are generally used when you want one QObject to spy on what is happening in another QObject, not to monitor events within a QObject itself.
Also, why are you deriving Menu from QWidget and not QMenu?