Qt QQuickWindow透明

Qt QQuickWindow透明,qt,Qt,我正在使用QQmlApplicationEngine和QQuickWindow作为应用程序,但我不能 透明的主窗口。我想在应用程序弹出之前设置一个启动,我使用窗口组件,它应该是透明的,但它不是,我的main.cpp是 int main(int argc, char *argv[]) { Application app(argc, argv); QShookaClient shooka_client; QQmlApplicationEngine engine; engine.rootContex

我正在使用QQmlApplicationEngine和QQuickWindow作为应用程序,但我不能 透明的主窗口。我想在应用程序弹出之前设置一个启动,我使用窗口组件,它应该是透明的,但它不是,我的main.cpp是

int main(int argc, char *argv[])
{
Application app(argc, argv);

QShookaClient shooka_client;
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("shooka", &shooka_client);
engine.load(QUrl("qrc:///shooka/shooka.qml"));

QObject *topLevel = engine.rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);

window->show();
window->setFlags(Qt::FramelessWindowHint);
window->setColor(Qt::transparent);

return app.exec();
}
intmain(intargc,char*argv[])
{
应用程序应用程序(argc、argv);
QShookaClient shooka_客户;
qqmlaplicationengine;
engine.rootContext()->setContextProperty(“shooka”和shooka_客户端);
发动机负荷(QUrl(“qrc:///shooka/shooka.qml"));
QObject*topLevel=engine.rootObjects().value(0);
QQuickWindow*window=qobject_cast(顶级);
窗口->显示();
窗口->设置标志(Qt::FramelessWindowHint);
窗口->设置颜色(Qt::透明);
返回app.exec();
}

但是setColor在win7中不起作用。我知道QQuestVIEW的方法,甚至我找到QQueVIEW的解决方案,它应该为QQueQueWindows工作,但不,任何人可以帮助我…< /P> < P>你可以考虑使用下面的代码来实现无框的透明窗口效果:

setWindowFlags(
        #ifdef Q_OS_MAC
            Qt::SubWindow |
        #else
            Qt::Tool |
        #endif
            Qt::FramelessWindowHint |
            Qt::WindowSystemMenuHint |
            Qt::WindowStaysOnTopHint
        );

setAttribute(Qt::WA_NoSystemBackground, true);
// set the parent widget's background to translucent
setAttribute(Qt::WA_TranslucentBackground, true);

setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
// create a display widget for displaying child widgets
QWidget* displayWidget = new QWidget;
displayWidget->setStyleSheet(".QWidget { background-color: rgba(0, 0, 0, 75%); border-width: 1px; border-style: solid; border-radius: 10px; border-color: #555555; } .QWidget:hover { background-color: rgba(68, 68, 68, 75%); border-width: 2px; border-style: solid; border-radius: 10px; border-color: #ffffff; }");

其思想是,父窗口或包含窗口没有框架,并且具有半透明背景。然后在父QWIDGET中嵌套一个子QWIDGET,并使用QSS来为透明应用样式。

< P>必须认识到<代码>窗口< /C> QtQuest类型映射到<代码> QQuaskWiels/Cuffo> C++类,并从<代码> QWiels中派生。根据Cameron的回答,可以设置窗口标志。但是您还需要将
不透明度设置为0.75以使其半透明。所有这些都可以在QML中完成,不需要设置C++的标志。
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.0

ApplicationWindow {
    title: qsTr("Hello World")
    width: 640
    height: 480
    flags: Qt.SubWindow | Qt.Tool | Qt.FramelessWindowHint | Qt.WindowSystemMenuHint | Qt.WindowStaysOnTopHint
    opacity: 0.75
    visible: true
    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }
    Button {
        text: "Hello World"
        anchors.centerIn: parent
    }
}


我知道这是一个老问题,但由于它没有被标记为已解决,我的方法如下:

import QtQuick 2.4
import QtQuick.Controls 1.3

ApplicationWindow {
    title: qsTr("Hello World")
    width: 640
    height: 480
    flags: Qt.FramelessWindowHint
    color: "transparent"
    visible: true
    Rectangle
    {
        color:"red"
        width: parent.width/2
        height: parent.height/2;anchors.centerIn: parent
    }
}

结果,你会得到一个透明的背景,中间有一个红色的矩形。您可以轻松更改图像的矩形


希望帮助了某人。

QWindow与QWidget不同。视图类都派生自QWidget.tanx,但问题是QWindow与QWidget不同。我不是qt方面的专家,我知道他们一定有关联……但真的有关联吗???QQuickWindow甚至没有像QWidget或QQuickView中的任何驱动器那样设置的属性……你们知道。我照你说的做了,但没用:我不知道win7有什么问题,我只是做错了。但我也只是复制并粘贴你的代码在我的,程序正在运行,任务在taskmanager中,但我的屏幕上没有任何内容。。。你知道吗?我还没有在Windows7下测试过。在Win7下使用angle还是opengl构建Qt?