Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The application does not minimize when you click on its icon in the taskbar using pyqt qml #8

Open
Jeinerox opened this issue Oct 1, 2024 · 1 comment

Comments

@Jeinerox
Copy link

Jeinerox commented Oct 1, 2024

Describe the bug
Hello! I'm having trouble figuring out why my application isn't minimizing when I use your library. I've noticed that when I combine your library with QQmlApplicationEngine, the application doesn't minimize when I click the icon in the taskbar. This only happens when I use this combination, though, as other PyQt classes work fine.

To Reproduce
Run this code and see if you can minimize the application by using the taskbar icon.

import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQml import QQmlApplicationEngine
import PyTaskbar 

if __name__ == '__main__':
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    engine.load('interface.qml')
    main_window = engine.rootObjects()[0]
    taskbar_progress = PyTaskbar.Progress(hwnd=int(main_window.winId()))
    taskbar_progress.init()  
    if not engine.rootObjects():
        sys.exit(-1)
    sys.exit(app.exec_())
import QtQuick 2.15
import QtQuick.Controls 2.15
ApplicationWindow {
    visible: true
    width: 400
    height: 300
    title: "Hello World"
    Rectangle {
        anchors.fill: parent
        color: "#ffffff"
        Text {
            text: "Hello, World!"
            anchors.centerIn: parent
            font.pixelSize: 32
            color: "#000000"
        }
    }
}

Expected behavior
The app should minimize when the icon is clicked in the taskbar.

@Jeinerox
Copy link
Author

Jeinerox commented Oct 1, 2024

I have no idea how this works, but adding a 5-second delay seems to solve the problem. However, having to wait 5 seconds each time before launching the app is a bit frustrating, to be honest. So, this isn't really a solution to the issue.

edit: It seems that Windows may be involved in this issue, causing the window to become a "ghost window". If you reduce the delay, Windows may not detect that the application has frozen, and minimizing the window may stop working again.

import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQml import QQmlApplicationEngine
import PyTaskbar 
from time import sleep

if __name__ == '__main__':
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    engine.load('interface.qml')
    main_window = engine.rootObjects()[0]
    sleep(5)
    taskbar_progress = PyTaskbar.Progress(hwnd=int(main_window.winId()))
    taskbar_progress.init()  
    if not engine.rootObjects():
        sys.exit(-1)
    sys.exit(app.exec_())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant