如何制作“真正的透明"窗口到光标,最好是在纯 QML 上?(Qt 5.7)
真实透明"解释(图片,76kb).
在该图像ApplicationWindow 上有一个视觉透明层.但实际上,光标并没有转到 ApplicationWindow 后面的窗口(本例中为 QT Creator).
On that image ApplicationWindow have a visually transparent layer. But in fact, cursor does not go to the window behind ApplicationWindow (in this case - QT Creator).
如果添加(取消注释)Qt.WindowTransparentForInput"标志,则实现真正的透明度",但按钮不再可用(这很明显,我知道).
"True Transparency" is achieved if add (uncomment) "Qt.WindowTransparentForInput" flag, but the buttons are no longer available (it's are obvious, I know).
我尝试了各种具有相似含义的标志(来自文档),但没有找到有效的组合 - 当光标位于窗口边界内时,光标处于默认"状态(必须处于文本"状态,因为那是它下面的文字).
I have tried a various flags with similar meanings (from the documentation), but did not find a working combination - cursor are stayind in "default" state when it is within borders of the window (must be in "text" state, because that are text below it).
是否有人遇到过类似的问题,您是否找到了解决方案?谢谢!
Did somebody faced with a similar problem, and are you find a solution? Thanks!
图像中的代码,其他项目文件保持不变(Qt Quick Controls 2 应用程序):
Code from image, other project files stayed untouched (Qt Quick Controls 2 Application):
import QtQuick 2.7
import QtQuick.Controls 1.5
ApplicationWindow {
visible: true
width: 320
height: 240
x: 400
y: 210
color: "transparent"
flags: Qt.Widget | Qt.FramelessWindowHint //| Qt.WindowTransparentForInput
//| Qt.WA_TranslucentBackground //| Qt.WA_NoSystemBackground
//| Qt.WA_NoBackground //| Qt.WA_MouseNoMask
Button {
x: ApplicationWindow.width - width
text: "Right Top Window Corner"
}
Button {
y: ApplicationWindow.height - height
text: "Left Bottom Window Corner"
}
}
推荐答案
一种解决方案是创建3个窗口,一个用于透明区域,一个用于每个按钮.
One solution is to create a 3 windows, one for the transparent area and one for each of the buttons.
import QtQuick 2.4
import QtQuick.Controls 1.5
import QtQuick.Window 2.0
ApplicationWindow {
id: app
visible: true
width: 320
height: 240
x: 400
y: 210
color: "transparent"
flags: Qt.Widget | Qt.FramelessWindowHint | Qt.WindowTransparentForInput | Qt.WindowStaysOnTopHint
Window {
visible: true
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
x: app.width - width
height: rightButton.implicitHeight
Button {
id: rightButton
text: "Right Top Window Corner"
}
}
Window {
visible: true
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
y: app.height - height
height: leftButton.implicitHeight
Button {
id: leftButton
text: "Left Bottom Window Corner"
}
}
}
相关文章