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

Exit full screen in WebEngineView QtQuick



  • Part of my QtQuick app will go fullscreen when the webpage requests it. I am able to successfully get into full screen when it is requested, however I seem to be unable to get out. I know I am doing something wrong. It seems to work initially and goes to my "else" and becomes fullscreen, but when I click the fullscreen web button again it does not seem to run again and exit fullscreen. Any help or guidance would be appreciated. The full code can be found here: https://gitlab.com/The3DmaN/media-server-connect

    mediaserverconnect.ui.qml

    WebEngineView {
            id: webview
            anchors.fill: parent
            settings.allowWindowActivationFromJavaScript: false
            settings.javascriptCanOpenWindows: true
            settings.javascriptEnabled: true
            settings.webGLEnabled: true
            settings.fullScreenSupportEnabled: true
            settings.showScrollBars: false
            url: "http://" + ipsettings.ip + ":" + ipsettings.port
    
            Connections {
                target: webview
                onFullScreenRequested: {
                    if (webview.state == "FullScreen") {
                        webview.triggerWebAction(WebEngineView.ExitFullScreen)
                        window.showNormal()
                        toolBar.visible = true
                    } else {
                        webview.state = "FullScreen"
                        window.showFullScreen()
                        toolBar.visible = false
                    }
                }
            }
        }
    

    Other info: The webpage is an Emby server video page, and the fullscreen button gives off the below code (not my code)

    function() {
      playbackManager.toggleFullscreen(currentPlayer)
    }
    


  • @The3DmaN said in Exit full screen in WebEngineView QtQuick:

    fullScreenSupportEnabled

    I haven't used this myself, but from looking at the documentation, perhaps you need to call request.accept() at the end of your onFullScreenRequested handler.

    Also, you could use the request.toggleOn property to query the mode rather than the string comparison with webview.state that you currently use.



  • @Bob64 Thanks so much! I think missing request.accept() was the issue. I also swapped to request.toggleOn.

    All working now with:

    onFullScreenRequested: {
                    if (request.toggleOn) {
                        window.showFullScreen()
                        toolBar.visible = false
                        request.accept()
       
                    } else {
                        window.showNormal()
                        toolBar.visible = true
                        request.accept()
                    }
                }
    

Log in to reply