2017-10-18 50 views
0

Hei buddy, 我想将透明窗口显示为触摸窗口(对于gst视频播放器,此视频播放器有三个窗口:1,balck-background; 2,视频图片; 3,触摸窗口)。 我们选择Qt4.7.4,一切似乎是确定我测试触摸之前window.I测试了QDeclarativeView和QWidget的,但他们都失败了,因为白色的背景,我的代码是这样的:如何在Qt4.7.4(QDeclarativeView或QWidget)上显示Ubuntu上的透明窗口?

////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

试试这个代码:

QDeclarativeView viewer; 
viewer.setProperty("windowOpacity", "value here"); 

您可以从0.0选择的任何值 - 1.0