嘿哥们, 我想将透明窗口显示为触摸窗口(对于gst视频播放器,此视频播放器有三个窗口:1,黑色背景; 2,视频图片; 3,触摸窗口)。 我们选择Qt4.7.4,在测试触摸窗口之前一切似乎都没问题。我测试了QDeclarativeView和QWidget,但它们都因为白色背景而失败,我的代码如下:
////main.cpp
QDeclarativeView viewer;
//viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer.setAttribute(Qt::WA_TranslucentBackground);
viewer.setStyleSheet("background:transparent;");
viewer.setBackgroundBrush(QColor(Qt::transparent));
//viewer.setBackgroundRole();
viewer.setSource(QUrl::fromLocalFile("qml/SanLiTest/main.qml"));
//viewer.setMainQmlFile(QLatin1String("qml/SanLiTest/main.qml"));
viewer.show();
//viewer.showExpanded();
//QWidget
QWidget* touch = new QWidget();
touch->setWindowOpacity(1);
touch->setWindowFlags(Qt::FramelessWindowHint);
touch->setAttribute(Qt::WA_TranslucentBackground);
touch->show();
/////////////////////////////////////////////////
main.qml
import QtQuick 1.1
Rectangle {
//width: Screen.desktopAvailableWidth
//height: Screen.desktopAvailableHeight
width: 1024
height: 600
color: "#00000000"
//opacity:0
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log("onClicked:", mouseX, mouseY);
}
}
// Component.onCompleted: {
// }
}
谢谢!
答案 0 :(得分:0)
试试这段代码:
QDeclarativeView viewer;
viewer.setProperty("windowOpacity", "value here");
您可以选择0.0到1.0之间的任何值