1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Calling QDialog.reject() has no effect - why? How do I close my dialog when certain...

Discussão em 'Python' iniciado por Stack, Setembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    Calling QDialog.reject() has no effect. What am I missing?

    from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QDialog, QVBoxLayout
    class MyDialog(QDialog):
    def __init__(self):
    super().__init__()
    print('MyDialog created')
    self.setWindowTitle('My Dialog')
    button = QPushButton('Close')
    button.clicked.connect(self.accept)
    self.setLayout(QVBoxLayout())
    self.layout().addWidget(button)
    self.reject()


    class MainWindow(QMainWindow):
    def __init__(self):
    super().__init__()
    button = QPushButton("Press Me!")
    button.clicked.connect(self.show_dialog)
    self.setCentralWidget(button)

    def show_dialog(self):
    d = MyDialog()
    rv = d.exec()
    if rv == QDialog.Accepted:
    print('Dialog accepted')
    else:
    print('Dialog rejected')


    app = QApplication([])
    window = MainWindow()
    window.show()
    app.exec()


    When running the program, the dialog shows up and I can press "Close". The return value is 'Accepted'. I would expect the dialog would either not show or close right away, and that the return value should be 'Rejected'

    What am I missing?

    Continue reading...

Compartilhe esta Página