Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2490

Rejected QMessageBox emits Accepted Signal

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 6.5.3
    • PySide
    • None

    Description

      If a QMessageBox is accepted by the user clicking a button, and then later "reject()" is called programmatically on the message box, the QMessageBox emits the "accepted()" signal instead of the "rejected()" signal.

      In PySide2, this did not occur. This is new to PySide6.

      Some sample code is pasted below. Note that when you click "Yes", "reject()" is called via QTimer, but it still emits "accepted()" instead of "rejected()".

      from PySide6.QtCore import QTimer
      from PySide6.QtWidgets import QApplication, QMessageBox
      
      app = QApplication()
      
      msg = 'Press "Yes"'
      standard_buttons = QMessageBox.StandardButton
      buttons = standard_buttons.Yes | standard_buttons.No
      box = QMessageBox(QMessageBox.Question, 'Question', msg, buttons)
      
      def accepted():
          print('Accepted!')
      
          # Now we will reject it later
          print('Now rejecting...')
          QTimer.singleShot(0, box.reject)
      
      def rejected():
          print('Rejected!')
      
      def finished():
          print('Finished!')
      
      box.finished.connect(finished)
      box.accepted.connect(accepted)
      box.rejected.connect(rejected)
      
      box.show()
      
      app.exec()
      
      Python 3.10.12
      Qt 6.6.1 (x86_64-little_endian-lp64 shared (dynamic) debug build; by GCC 11.4.0) [Python limited API 3.10.12]
      Accepted #0
      Now rejecting...
      Finished #0!
      Accepted #1
      Finished #1!
      
      Python 3.10.12
      Qt 5.15.14 (x86_64-little_endian-lp64 shared (dynamic) debug build; by GCC 11.3.0)
      Accepted #0
      Now rejecting...
      Finished #0!
      Rejected #0!
      Finished #1!
      

      Attachments

        1. pyside2490.py
          1 kB
          Friedemann Kleint

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              psavery Patrick Avery
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes