简体   繁体   中英

How to trigger a pyqt5 signal when closing a window

i want to fire a pyqt signal to reopen the menu every time the other windows are closed, i think the class QMainWindow doesn't have a .closed signal, can you help me?

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication
import Caixa
import Estoque
import Relatorio

app = QApplication(sys.argv)
menu = uic.loadUi(r'window/menu.ui')


caixa = Caixa.Window()
estoque = Estoque.Window()
relatorio = Relatorio.Window()

# gatilhos
menu.caixa.clicked.connect(lambda: caixa.open())
menu.caixa.clicked.connect(lambda: menu.close())

menu.produtos.clicked.connect(lambda: estoque.open())
menu.produtos.clicked.connect(lambda: menu.hide())

menu.relatorio.clicked.connect(lambda: relatorio.open())
menu.relatorio.clicked.connect(lambda: menu.hide())

estoque.window.exit.triggered.connect(lambda: menu.show())
caixa.window.exit.triggered.connect(lambda: menu.show())
relatorio.window.exit.triggered.connect(lambda: menu.show())

menu.show()
sys.exit(app.exec_())

You could use the "atexit" handler. atexit Documents

In my example

import atexit

atexit.register(/*call your function here*/)

So when the window closes it registers a signal and calls the function in need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM