N3RDIUM / PyTaskbar

The Ultimate python taskbar progress package!
MIT License
18 stars 4 forks source link

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

Open Jeinerox opened 1 month ago

Jeinerox commented 1 month ago

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 commented 1 month ago

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