qml 拖拽窗体(算法实现)去掉窗体标题栏

试验成功 代码如下:  

import QtQuick2.2

import QtQuick.Window 2.1
import QtQuick 2.0

Window {
    id:window
    visible: true
    width: 850
    height: 500
    property int xx: window.x
    property int yy: window.y
    property int xx1: 0
    property int yy1: 0
    x:xx;
    y:yy
    MouseArea {                         //    拖拽窗体
        id: dragArea
        anchors.fill: control
        hoverEnabled: true
        onPressed: {
            xx1=mouseX
            yy1=mouseY
        }
        onPositionChanged: {
            if(xx1!=0&&yy1!=0){
                xx=xx+(mouseX-xx1);
                yy=yy+(mouseY-yy1);
            }
        }
        onReleased: {
            xx1=0
            yy1=0
        }
    }
/*设置 哪里是 可以拖拽的 区域*/
     Rectangle{
id:control x:0;y:0 
        width:window.width;height: 70
        color:"green"
    }
/*******去掉qml窗体标题框******/
Component.onCompleted: {
        window.flags = 0x0000080
    }

 }


 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现自定义标题栏可以通过使用QML中的Rectangle等组件来实现,并在其中添加需要的控件,例如按钮、标签、图标等。同时,为了实现与原生窗体相似的功能,可以使用QML中的Window组件,并将其属性设置为透明,然后在自定义标题栏中添加控件时,将它们放置在Window组件的边缘位置,以达到与原生窗体相似的效果。此外,还可以通过使用QML中的MouseArea组件来实现拖拽窗口的功能。具体实现方法可以参考以下示例代码: ``` import QtQuick 2.15 import QtQuick.Window 2.15 Window { visible: true width: 640 height: 480 title: "" Rectangle { id: titleBar width: parent.width height: 30 color: "#2d2d2d" MouseArea { anchors.fill: parent drag.target: parent } Label { text: "Custom Title Bar" font.bold: true color: "#ffffff" anchors.centerIn: parent } Button { text: "X" font.bold: true color: "#ffffff" anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter onClicked: { Qt.quit(); } } } Rectangle { id: content anchors.top: titleBar.bottom anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom color: "#ffffff" } } ``` 在这个示例中,我们使用了一个Rectangle组件作为自定义标题栏,并在其中添加了一个Label和一个Button。为了实现拖拽窗口的功能,我们在自定义标题栏上添加了一个MouseArea组件,并将drag.target设置为父组件。另外,我们还使用了另一个Rectangle组件作为窗口的内容区域,并通过anchors属性将其与自定义标题栏对齐。最后,我们将Window的title属性设置为空字符串,以隐藏原生窗口的标题栏
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值