Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Using QTimer.SingleShot to Report Minimizedness Gets the State Wrong
Forum Updated to NodeBB v4.3 + New Features

Using QTimer.SingleShot to Report Minimizedness Gets the State Wrong

Scheduled Pinned Locked Moved Unsolved Qt for Python
9 Posts 3 Posters 225 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johnzhou721
    wrote last edited by
    #1

    See the following snippet.

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

    The system already displays the window as minimized after I call the showMinimized function, and immediately reporting the state works correctly; however, if I wait a few seconds and then do it, it somehow actually gets the state wrong? What is this because of? Thanks!

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote last edited by jeremy_k
      #2

      Which operating system and Qt release are being used?

      I am not seeing this with macOS 15 and Qt 6.8.3 using an equivalent C++ program:

      #include <QApplication>
      #include <QWidget>
      #include <QDebug>
      #include <QTimer>
      
      void monitor_and_report(QWidget *window)
      {
          qDebug() << "window.isMinimized():" <<  window->isMinimized()
                   << "windowState has Qt.WindowMinimized flag:"
                   << (window->windowState() & Qt::WindowState::WindowMinimized);
      }
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QWidget w;
          w.showMinimized();
          monitor_and_report(&w);
          QTimer::singleShot(1500, [&w]{ monitor_and_report(&w); });
          return a.exec();
      }
      

      Output:

      window.isMinimized(): true
      windowState has Qt.WindowMinimized flag: QFlags<Qt::WindowState>(WindowMinimized)
      window.isMinimized(): true
      windowState has Qt.WindowMinimized flag: QFlags<Qt::WindowState>(WindowMinimized)
      

      You could try monitoring the QWindow::windowStateChanged() signal or WindowStateChange event.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      2
      • J Offline
        J Offline
        johnzhou721
        wrote last edited by johnzhou721
        #3

        @jeremy_k

        I installed PySide6 through pip. Version: plasmashell 6.3.4

        Fedora KDE spin 42.

        Also somehow compiling the program on fedora does not seem to give me any printing.

        EDIT Hmm... seems like a Qt bug, it works on my macOS as well.

        Any tips? Thanks

        jeremy_kJ 1 Reply Last reply
        0
        • J johnzhou721

          @jeremy_k

          I installed PySide6 through pip. Version: plasmashell 6.3.4

          Fedora KDE spin 42.

          Also somehow compiling the program on fedora does not seem to give me any printing.

          EDIT Hmm... seems like a Qt bug, it works on my macOS as well.

          Any tips? Thanks

          jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote last edited by
          #4

          @johnzhou721 said in Using QTimer.SingleShot to Report Minimizedness Gets the State Wrong:

          @jeremy_k

          I installed PySide6 through pip. Version: plasmashell 6.3.4

          Fedora KDE spin 42.

          I'm presuming that plasmashell is the KDE shell, which may not have anything to do with the Qt version. pypi.org doesn't list a corresponding package via the web search interface. Qt 6.3 was released in 2022. Fedora 42 was released in 2025. I would try upgrading to a more recent Qt release.

          Getting the Qt version from PySide:

          #!/usr/bin/env python3
          from PySide6.QtCore import qVersion
          print(qVersion())
          

          Also somehow compiling the program on fedora does not seem to give me any printing.

          Does compiling refer to invoking a C++ or other language compiler, or running the resulting program? Printing as in writing text to the console? What does the code look like?

          EDIT Hmm... seems like a Qt bug, it works on my macOS as well.

          It could be. It could be intentional windowing system behavior. I can only speculate without code.

          Asking a question about code? http://eel.is/iso-c++/testcase/

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote last edited by
            #5

            Hi,

            Are you running wayland as window manager ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • J Offline
              J Offline
              johnzhou721
              wrote last edited by
              #6

              @jeremy_k I have 6.9.1 using your test script. Sorry about all this vagueness.

              @SGaist echo $XDG_SESSION_TYPE gives wayland.

              Thanks!

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote last edited by
                #7

                Would it be possible to try it under Xorg to see if you have a different behavior ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  johnzhou721
                  wrote last edited by
                  #8

                  @SGaist Unfortunately installing the xorg backend seems to get my login screen frozen (except cursor) on logout... since I had to force a shutdown from my VM and something bad happened I ended up reinstalling, and I don't want to deal with this again... there's advice telling me to use plasma-workspace-x11-6.0.3-1.fc40.x86_64.rpm online to deal with this but then I use an ARM64 VM... how should I be delaing with this if testing on X11 is impossible?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote last edited by
                    #9

                    For the package, there's likely an ARM version available.

                    The thing is:

                    • it might be a wayland issue
                    • it might be a composer issue
                    • it might be a Qt/KDE issue

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved