问题
"True Transparency" explanation (image, 76kb).
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).
"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!
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"
}
}
回答1:
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"
}
}
}
来源:https://stackoverflow.com/questions/40833624/how-to-make-a-true-transparent-window-to-cursor-preferably-on-a-pure-qml-qt