1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| #!/usr/bin/env python3
# coding: utf-8
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class myWidget(QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__btn=QPushButton("Autre fenêtre", parent=self, clicked=self.__slotSubWinOn)
mainLayout=QVBoxLayout(self)
mainLayout.addWidget(self.__btn, stretch=0)
self.resize(300, 200)
self.__other=mySubWin()
self.__other.setVisible(False)
self.__other.sigClose.connect(self.__slotSubWinOff)
# __init()
def __slotSubWinOn(self):
self.__btn.setDisabled(True)
self.__other.show()
# __slotSubWinOn()
def __slotSubWinOff(self):
self.__btn.setEnabled(True)
# __slotSubWinOff()
# class myWidget
class mySubWin(QWidget):
sigClose=pyqtSignal()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__btn=QPushButton("Fermer", parent=self, clicked=self.close)
mainLayout=QVBoxLayout(self)
mainLayout.addWidget(self.__btn, stretch=0)
self.resize(180, 150)
# __init__()
def closeEvent(self, event):
print(
"%s => %s.closeEvent(%s)" % (
self.sender().__class__.__name__,
self.__class__.__name__,
"%s (%s)" % (event.__class__.__name__, type(event)),
)
)
self.sigClose.emit()
super().closeEvent(event)
# closeEvent()
# mySubWin()
if __name__ == "__main__":
appli=QApplication(sys.argv)
widget=myWidget()
widget.show()
sys.exit(appli.exec_())
# if |
Partager