PyQt5 按钮在通过堆叠小部件 setCurrentWidget 出现在屏幕上时获得点击信号

PyQt5 button gets clicked signal when appeared on screen through stacked widget setCurrentWidget

我有一个带有 window 和 QStackedWidget 的应用程序。单击(或触摸)时,堆叠小部件的第一页消失并更改为第二页。第二页有个按钮。

class AppLauncher(QtWidgets.QMainWindow, AppWindow.Ui_MainWindow):
    def __init__(self, parent=None):
        super(AppLauncher, self).__init__(parent)
        self.setupUi(self)
        self.iddle = True
        self.fooButton.clicked.connect(self.foo)

    def foo(self):
        pass

    def eventFilter(self, obj, event):
        if (event.type() == QEvent.TouchBegin or \
            event.type() == QEvent.TouchUpdate or \
            event.type() == QEvent.MouseButtonPress) and self.manager_initialised :
                
                if self.iddle:
                    self.stackedScreens.setCurrentWidget(self.buttonPage)

        return super(AppLauncher, self).eventFilter(obj, event)

def main():
    app = QApplication(sys.argv)
    form = AppLauncher()
    form.setAttribute(QtCore.Qt.WA_AcceptTouchEvents, True)
    form.installEventFilter(form)
    form.show()
    
    app.exec_()
    
if __name__ == '__main__':
    main()

它工作正常,但如果我触摸第一页上第二页按钮所在的区域,页面会立即改变并且按钮会出现在手指下方。当我松开手指时,按钮会收到“点击”信号。
这种情况发生得如此之快,以至于即使快速点击第一页也会触发信号。
这可能会导致用户在触摸第一页后不明白他们点击了按钮。

我该如何解决这个问题?我认为只有在按钮出现后放开手指才会触发点击信号。

检查 mouseButtonRelease

class AppLauncher(QtWidgets.QMainWindow, AppWindow.Ui_MainWindow):
    def __init__(self, parent=None):
        super(AppLauncher, self).__init__(parent)
        self.setupUi(self)
        self.iddle = True
        self.fooButton.clicked.connect(self.foo)

    def foo(self):
        pass

    def eventFilter(self, obj, event):
        if (event.type() == QEvent.TouchBegin or \
            event.type() == QEvent.TouchUpdate or \
            event.type() == QEvent.MouseButtonRelease) and self.manager_initialised :
                
                if self.iddle:
                    self.stackedScreens.setCurrentWidget(self.buttonPage)

        return super(AppLauncher, self).eventFilter(obj, event)

def main():
    app = QApplication(sys.argv)
    form = AppLauncher()
    form.setAttribute(QtCore.Qt.WA_AcceptTouchEvents, True)
    form.installEventFilter(form)
    form.show()
    
    app.exec_()
    
if __name__ == '__main__':
    main()