Using QTimer.SingleShot to Report Minimizedness Gets the State Wrong
-
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!
-
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.
-
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
-
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
@johnzhou721 said in Using QTimer.SingleShot to Report Minimizedness Gets the State Wrong:
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.
-
Hi,
Are you running wayland as window manager ?
-
Would it be possible to try it under Xorg to see if you have a different behavior ?
-
@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? -
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