'Minimizing window issue in Qt 5.15

Window {
    id: mainWindow

    width: 960
    height: 600

    flags:  Qt.FramelessWindowHint | Qt.WindowMinimizeButtonHint | Qt.Window

    Rectangle {
        width: 15
        height: 15

        anchors {
            top: parent.top
            left: parent.left
            
            topMargin: 10
            leftMargin: 910
        }

        SvgImage {
            width: 11
            height: 2

            source: "images/Collapse.svg"

            anchors {
                centerIn: parent
            }
        }

        MouseArea {
            id: mouse
    
            anchors {
                fill: parent
            }
            
            onPressed: {
                mainWindow.showMinimized()
            }
        }
     
        Timer {
            repeat: true
            interval: 1000
            running: true

            onTriggered: {
                console.log("mouse.pressed = ", mouse.pressed);
            }
        }
    }
}

I faced an issue with Qt.FramelessWindowHint. After using showMinimized() function I restore the window but then any click on window causes minimizing window again. mouseArea never gets pressed. I tried putting Timer printing mouse.pressed valueand it's false all the time. I found the several links on this issue but there's no solution except going to fullscreen when restoring window. My application always stays the same size and never goes to fullscreen.

https://www.qtcentre.org/threads/33298-Qt-FramelessWindowHint-qgraphicsview-qgraphicwidget-showminimized-problem

https://www.qtcentre.org/threads/42641-QML-rendering-problems-after-showMinimized()

QML: rendering problems after showMinimized()

Maybe you could give me a hint for workaround. Btw I'm using Qt 5.15



Solution 1:[1]

Use onClicked insted of onPressed inside the MouseArea.

Solution 2:[2]

In fact, I could not see any windows after running your code I add visible: true and I removed SvgImage.

This is what I run:

import QtQuick 2.15
import QtQuick.Window 2.15

Window {
    id: mainWindow

    width: 960
    height: 600
    visible: true

    flags:  Qt.FramelessWindowHint | Qt.WindowMinimizeButtonHint | Qt.Window


    Rectangle {
        width: 15
        height: 15
        color: "#f50909"

        anchors {
            top: parent.top
            left: parent.left

            topMargin: 10
            leftMargin: 910
        }

        MouseArea {
            id: mouse

            anchors {
                fill: parent
            }

            onPressed: {
                mainWindow.showMinimized()
            }
        }


    }


}

This is my result and it works correctly:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andronicus
Solution 2 Parisa.H.R