Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-118226

Rejected QMessageBox emits Accepted Signal

    XMLWordPrintable

Details

    • b30121041 (dev), 8a8481f7e (6.7), 4266bf601 (6.6), f5de35783 (tqtc/lts-6.5)

    Description

      This issue is being transferred from https://bugreports.qt.io/browse/PYSIDE-2490

      It occurred with Qt 6.5.3. I tried to make a minimal C++ example to reproduce the issue, but the issue did not occur for my C++ example (perhaps because I was using a different version of Qt - 6.2.4, which I can install on Ubuntu without compiling Qt). That example is attached.

      Pasted below is my original message (the issue occurred on multiple operating systems):

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

      Attachments

        1. qtbug118226.zip
          2 kB
        2. testbug.tgz
          1.0 kB

        Issue Links

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

          Activity

            People

              vestbo Tor Arne Vestbø
              psavery Patrick Avery
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews