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
I know this is an old question, but as it is not marked as solved, here is my approach:
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
}
}
As result, you will get a transparent background with a red rectangle in the middle. You could easily change that rectangle for an image.
Hope helped someone.
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.
One has to realize that a Window
QtQuick type maps to QQuickWindow
C++ class, and derives from QWindow
. The window flags, per Cameron's answer, can be set. But you also need to set the opacity
to, say, 0.75 to make it translucent. All of this can be done in QML, no need for setting flags from 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
}
}