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

Reading Window State Under QTimer Causes Wrong State

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 6.9.1
    • None
    • Fedora KDE Spin running in UTM / QEMU, Wayland, all packages updated, PySide6 installed through system [note: have to update all packages after installing pyside6 through system under this distro else it will blackscreen on next boot.]
    • Linux/Wayland

      Using QTimer.SingleShot to read the window state of a window in Qt gets it wrong.  PySide6 reproducer:

      import sys
      from PySide6.QtWidgets import QApplication, QWidget
      from PySide6.QtCore import Qt, QTimer
       
      def monitor_and_report(window):
          state = window.windowState()
          is_min = window.isMinimized()
          flag_min = bool(state & Qt.WindowMinimized)
          print("window.isMinimized():", is_min)
          print("windowState has Qt.WindowMinimized flag:", flag_min)
       
      def main():
          app = QApplication(sys.argv)
       
          window = QWidget()
          window.setWindowTitle("Minimized Window + Qt event loop")
          window.resize(400, 200)
          window.showMinimized()
          monitor_and_report(window)
       
          QTimer.singleShot(1500, lambda: monitor_and_report(window))
       
          sys.exit(app.exec())
       
      if __name__ == "__main__":
          main()

       gives me both True for the first round and both False for the second one.  There is no unminimizing done in the GUI during these two reports.

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

            vestbo Tor Arne Vestbø
            johnzhou721 John Zhou
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes