如何在 QtWidgets.QDialog 关闭事件中做某事
How to do something in QtWidgets.QDialog close event
我正在使用 self.sub_dialog = QtWidgets.QDialog(self)
我想在 sub_dialog 关闭事件时清除 QLineEdite。怎么办?
我想你想要这个
from PyQt5.QtWidgets import *
class main(QWidget):
def __init__(self):
super().__init__()
self.line_main = QLineEdit("Line", self)
self.resize(800,500)
self.show()
self.dialog = QDialog(self)
self.line = QLineEdit("Line", self.dialog)
self.dialog.resize(400,300)
self.dialog.closeEvent = self.line_clear
self.dialog.exec_()
self.resize(800,500)
self.show()
def line_clear(self, event):
if self.line.text() != "":
self.line_main.clear()
self.line.clear()
print("Success")
app = QApplication([])
window = main()
app.exec()
我正在使用 self.sub_dialog = QtWidgets.QDialog(self)
我想在 sub_dialog 关闭事件时清除 QLineEdite。怎么办?
我想你想要这个
from PyQt5.QtWidgets import *
class main(QWidget):
def __init__(self):
super().__init__()
self.line_main = QLineEdit("Line", self)
self.resize(800,500)
self.show()
self.dialog = QDialog(self)
self.line = QLineEdit("Line", self.dialog)
self.dialog.resize(400,300)
self.dialog.closeEvent = self.line_clear
self.dialog.exec_()
self.resize(800,500)
self.show()
def line_clear(self, event):
if self.line.text() != "":
self.line_main.clear()
self.line.clear()
print("Success")
app = QApplication([])
window = main()
app.exec()