简体   繁体   English

如何在 QtWidgets.QDialog 关闭事件中做某事

[英]How to do something in QtWidgets.QDialog close event

i am using self.sub_dialog = QtWidgets.QDialog(self) I want to clear a QLineEdite when the sub_dialog closing event.我正在使用self.sub_dialog = QtWidgets.QDialog(self)我想在 sub_dialog 关闭事件时清除 QLineEdite。 How to do?怎么做?

I think you want this我想你想要这个

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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