user3030327
user3030327

Reputation: 451

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. How to do?

Upvotes: 0

Views: 2780

Answers (1)

SimoN SavioR
SimoN SavioR

Reputation: 604

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

Upvotes: 1

Related Questions