ฉันต้องการจะปิดทั้งหน้าต่างอื่นทั้งหมดที่เปิดอยู่โดยที่หน้าต่างหลักเมื่อตอนที่หน้าต่างหลักปิดไปแล้ว
ได้โปรดตามหาอยู่ด้านล่างมิน รหัสที่ฉันกำลังทดสอบ:
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QVBoxLayout, QWidget
import sys
class AnotherWindow(QWidget):
"""
This "window" is a QWidget. If it has no parent, it
will appear as a free-floating window as we want.
"""
def __init__(self):
super().__init__()
layout = QVBoxLayout()
self.label = QLabel("Another Window")
layout.addWidget(self.label)
self.setLayout(layout)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.button = QPushButton("Push for Window")
self.button.clicked.connect(self.show_new_window)
self.setCentralWidget(self.button)
def show_new_window(self, checked):
self.w = AnotherWindow()
self.w.show()
def close_another_window(self):
if self.w:
self.w.close()
app = QApplication(sys.argv)
w = MainWindow()
app.aboutToQuit.connect(w.close_another_window)
w.show()
app.exec()
ที่แสดงอยู่เหนือฉันพยายามใช้ aboutToQuit
ตัวเลือกของ QApplication
แต่มันนี้แต่จะโทรหาเมื่อตอนที่อีกหน้าต่างด้วมันปิดไปแล้ว
ฉันต้องการจะปิดในอีกหน้าต่าง automaticaly ตอนที่หน้าต่างหลักปิดไปแล้ว