在用qml做不规则和半透明窗口的,时候,一般会知道
Window {
id:window
color: "#00000000"
flags: Qt.FramelessWindowHint
width: 800
height: 600
}
设置了无边框和背景透明之后,会发现有一个bug
就是透明区域会相应鼠标点击事件,
这个一般不是我们希望的,
如何才能不让它不想要不必要的鼠标事件呢
QRegion QWindow::mask() const
Returns the mask set on the window.
The mask is a hint to the windowing system that the application does not want to receive mouse or touch input outside the given region.
可以设置一下mask,可以屏蔽掉不在区域类的鼠标事件
使用setMask函数实现,但是setMask是c++函数,没有导出给qml使用,
目前想到的办法就是使用c++实现给窗口,再给qml使用
这样就可以实现了,但是如果需要做更复杂类似悬浮框,点击然后弹框用着用办法qml做出来可能不行,
因为一个窗口区域用mask还是比较方便的,但是如果有多个窗口区域,而且会变更,如果使用qml实现,可能做不到,因为
需要动态的从qml中获取他的QRegion,然后设置给setMask(QRegion),才能实现,但是qml(比如Window,Popup,Rectangle等)
都不支持获取Region,所有使用qml实现是不行的。
可以用C++,Qt的方式实现