QQuickWindow transparent

前端 未结 3 1018
醉话见心
醉话见心 2021-01-05 02:40

im using QQmlApplicationEngine with QQuickWindow for an application and i can\'t transparent main window. i want to set a splash before application pops up and i use Window

3条回答
  •  情深已故
    2021-01-05 03:28

    You might consider using the following code for achieving a frameless transparent window effect:

    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; }");
    

    The idea is that your parent window or containing window has no frame and has a translucent background. Then you nest a child QWidget inside the parent QWidget and apply styles using QSS for transparency.

提交回复
热议问题