Qml window framelesswindowhint hide title

39 Views Asked by At

I'm here for the first time, I'm a beginner . Help me clear up a problem. When I want to restore the window, top in the left corner appears the title. Please press the red button, then restore the window. Thank you for your help

import QtQuick
import QtQuick.Window
import QtQuick.Controls



ApplicationWindow {
    id: window
    width: 700
    height:500
    color: "#00000000"

    flags: Qt.Window | Qt.FramelessWindowHint


    property alias windowBg: windowBg
    property alias btnMinimize: btnMinimize
    property alias btnMaximize: btnMaximize
    property alias btnClose: btnClose

    // Propeties
    property int windowStatus: 1
    property int windowMargin: 30

    // Internal functions
    QtObject{
        id: internal

        function resetResizeBorders(){
            // Resize visibility
            resizeLeft.visible = true
            resizeRight.visible = true
            resizeBottom.visible = true
        }

        function maximizeRestore(){
            if(windowStatus == 0){
                window.showMaximized()
                windowStatus = 1
                windowMargin = 0
                // Resize visibility
                resizeLeft.visible = false
                resizeRight.visible = false
                resizeBottom.visible = false
            }
            else{
                window.showNormal()
                windowStatus = 0
                windowMargin = 30
                // Resize visibility
                internal.resetResizeBorders()
            }
        }

        function ifMaximizedWindowRestore(){
            if(windowStatus == 1){
                window.showNormal()
                windowStatus = 0
                windowMargin = 30
                internal.resetResizeBorders()
            }
        }

        function restoreMargins(){
            windowStatus = 0
            windowMargin = 30
            internal.resetResizeBorders()
        }
    }

    Rectangle {
        id: windowBg
        radius: windowStatus ? 0 : 6
        anchors.fill: parent
        anchors.margins: windowMargin
        z: 1

        Row {
            id: rowBtns
            width: 105
            height: 35
            anchors.right: parent.right
            anchors.top: parent.top
            anchors.topMargin: 0
            anchors.rightMargin: 20
            z: 1
            Button{
                id: btnMinimize
                width: 40
                height: width
                objectName: 'minimize'
                onClicked: {
                    window.showMinimized()
                    internal.restoreMargins()
                }
                background: Rectangle{
                    color: 'red'
                }
            }

            Button {
                id: btnMaximize
                width: 40
                height: width
                objectName: 'maximize'
                onClicked: internal.maximizeRestore()
                background: Rectangle{
                    color: 'green'
                }
            }

            Button {
                id: btnClose
                width: 40
                height: width
                objectName: 'close'
                onClicked: window.close()
                background: Rectangle{
                    color: 'yellow'
                }
            }
        }
    }

    MouseArea {
        id: resizeLeft
        width: 10
        anchors.left: parent.left
        anchors.top: parent.top
        anchors.bottom: parent.bottom
        anchors.leftMargin: 0
        anchors.bottomMargin: 10
        anchors.topMargin: 10
        cursorShape: Qt.SizeHorCursor

        DragHandler{
            target: null
            onActiveChanged: {
                if (active) { window.startSystemResize(Qt.LeftEdge) }}
        }
    }

    MouseArea {
        id: resizeRight
        width: 10
        anchors.right: parent.right
        anchors.top: parent.top
        anchors.bottom: parent.bottom
        anchors.rightMargin: 0
        anchors.bottomMargin: 10
        anchors.topMargin: 10
        cursorShape: Qt.SizeHorCursor

        DragHandler{
            target: null
            onActiveChanged: if (active) { window.startSystemResize(Qt.RightEdge) }
        }
    }

    MouseArea {
        id: resizeBottom
        height: 10
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.rightMargin: 10
        anchors.leftMargin: 10
        anchors.bottomMargin: 0
        cursorShape: Qt.SizeVerCursor

        DragHandler{
            target: null
            onActiveChanged: if (active) { window.startSystemResize(Qt.BottomEdge)}
        }
    }

    MouseArea {
        id: moveWindow
        height: 40
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.top: parent.top
        anchors.topMargin: 0
        anchors.rightMargin: 0
        anchors.leftMargin: 10

        DragHandler {
            target: null
            onActiveChanged: if(active){
                                 window.startSystemMove()
                                 internal.ifMaximizedWindowRestore()
                             }
        }
        onDoubleClicked: internal.maximizeRestore()


    }

    Component.onCompleted:{
        internal.maximizeRestore()
    }
}

example

I tried to look for some information on the forum, so and I did not find

0

There are 0 best solutions below