-1
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

BrutalWizard
  • 495
  • 1
  • 9
  • 19
Valeriia
  • 586
  • 2
  • 4
  • 21
  • what is `SvgImage`? I think your Bug was because of that. remove it and try my example too. you can add an `SVG` image in `Image { }`. – Parisa.H.R Mar 31 '22 at 19:22

2 Answers2

1

Use onClicked insted of onPressed inside the MouseArea.

Andronicus
  • 25,419
  • 17
  • 47
  • 88
amutka
  • 26
  • 1
0

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

Parisa.H.R
  • 3,303
  • 3
  • 19
  • 38
  • Removing SvgImage and clicking on rectangle item gives the same result.Steps to reproduce the bug: click on theitem so to minimize the window, Click on application item on the task bar in order to show it again, click in any place of the window (not rectangle item) - the result - it's minimized again and it's wrong – Valeriia Apr 01 '22 at 09:37
  • @Valeriia what are your `Qt Version` and `Os` and `compiler`? because I try it and it works OK for me. My Os is ubuntu 20.04 and I use Qt 6.2.3, `GCC` compiler. – Parisa.H.R Apr 01 '22 at 12:33
  • Maybe your window `focus` was changed or maybe that relates to your qt version or maybe this happens on windows. I don't know if you use windows or not but I had a similar problem in past with windows. – Parisa.H.R Apr 01 '22 at 13:01
  • I use Windows 10 and Qt 5.15 with Qmake compiler – Valeriia Apr 01 '22 at 13:19
  • @Valeriia I suggest you test qt in ubuntu in VMWare,I am sure this code is logically correct and works correctly. – Parisa.H.R Apr 01 '22 at 13:26
  • I think so too but I need to run it successfully on Windows, that's why I asked for any kind of workaround – Valeriia Apr 01 '22 at 13:44