[Solved] How can I have a irregular-shaped window with Qt 5.2? WA_TranslucentBackground doesn't work on Qt 5.2 Windows
-
Hi,
The code below opens a borderless window with qml UI and black background.
@
#include <QQuickView>
#include "mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
setFixedSize(300, 300);
setWindowFlags(Qt::FramelessWindowHint);
setStyleSheet("background :transparent;");
//setAttribute(Qt::WA_TranslucentBackground, true);view = new QQuickView(); view->setSource(QUrl("main.qml")); view->setColor(QColor(Qt::transparent)); container = QWidget::createWindowContainer(view, this); container->setFixedSize(300, 300); container->setGeometry(10, 10, 30, 30); container->setFocusPolicy(Qt::TabFocus);
}
MainWindow::~MainWindow()
{
delete container;
delete view;
}
@But, if I remove the remark of below line, the window becomes completely invisible.
@
setAttribute(Qt::WA_TranslucentBackground, true);
@Is it a bug?
How can I have a irregular-shaped window with Qt 5.2?
Thank you,
Cid
-
Bump... Anyone has a solution for this?
I have run into similar problem. Transparency works fine just for QQuickView window alone:
@
view = new QQuickView();
view->setSource(QUrl("main.qml"));
view->setColor(QColor(Qt::transparent));
view->show();
@But once I try to create a window container for my QQuickView with QWidget::createWindowContainer(...), I get either opaque black background or invisible nothing.
Is this a bug? Is there at least a workaround?
-
Hi,
I have the same problem - did you ever get a workaround for this?
Thank you,
Bruno -
Hi,
I have the same problem
Can anybody help?
Thank you, -
There are 2 ways. One is QWidget with QDeclarativeView like Qt 4. Another is QQuickView.
For the former, WA_TranslucentBackground works, but Qml 2 not support.
For the latter, a mask picture is required. Below is the sample code:
@
MainView::MainView(QQuickView *parent) :
QQuickView(parent)
{
Qt::WindowFlags _flags = flags();
_flags |= Qt::FramelessWindowHint;
setFlags(_flags);
setSource(QStringLiteral("default/main.qml"));show();
setMask(QPixmap("default/mask.png").mask());
}@
mask.png is the picture with alpha channel. It is the shape of window shape.
Hope this helps to you.
Mao-Yeh