Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Can not hide window after called showNormal() when window is FullScreen state



  • This following code shows the problem on macOS. I can't hide the window after called showNormal() function, the window keeps showing. What the best way to hide window after called showNormal() when window is FullScreen?

    I'm using Qt 5.14.2/5.15.0
    OS: macOS 10.15.6

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.12
    import QtQuick.Layouts 1.12
    
    Window {
        id: mainWindow
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Component.onCompleted: {
            mainWindow.showFullScreen()
        }
    
        RowLayout {
            anchors.centerIn: parent
    
            Button {
                text: qsTr('Hide')
                onClicked: {
                   if (mainWindow.visibility === Window.FullScreen) {
                       mainWindow.showNormal()
                       mainWindow.visible = false
                   } else {
                       mainWindow.visible = false
                   }
                }
            }
        }
    }
    

Log in to reply