Transparent window in Qt - c++

How can I create a transparent window in Qt for Linux. I tried the following, but it doesn't work:
myWidget::myWidget(QWidget *parent) : QWidget(parent, Qt::FramelessWindowHint) {
setWindowOpacity(0.4);
}

"Note that under X11 you need to have
a composite manager running, and the
X11 specific _NET_WM_WINDOW_OPACITY
atom needs to be supported by the
window manager you are using."
https://doc.qt.io/qt-5/qwidget.html#windowOpacity-prop
What window manager are you using?
http://en.wikipedia.org/wiki/Compositing_window_manager#List_of_compositing_window_managers
Does your server support the "Composite extension"?
http://en.wikipedia.org/wiki/Composite_(graphics)
Does your card support it?

Try to use QGraphicsOpacityEffect and QWidget::setGraphicsEffect

I had a similar issue but on windows, not sure if it will help in Linux
Instead of Qt::FramelessWindowHint use Qt::SplashScreen. I can have a frameless and transparent window on top of my other widgets.

Related

mouse click from mpv in qt

I'm writing a Qt application which uses mpv for playing different videos.
QWidget is used to show video content. I also have custom dock with controls for switching video channels, changing position, etc.
I want to have dock appearing after a click on the screen and disappearing on timer event. It all works fine, except from the fact, that QWidget used for mpv is not receiving QMouseEvent. On the contrast same event works fine for main window. Basically dock appears only if you click on visible part of main window and not on mpv Qwidget.
I assume it is because mpv has internal support for keybindings. I've tried to disable them by setting "input-default-bindings" to "no", but it didn't help.
mpv_set_option_string(mpv, "input-default-bindings", "no");
Can anybody help with that?
Does anybody know how to configure keybindings for mpv (I can't find any example in documentation)?
Maybe there is a workaround for it?
Thanks a lot.
You can use a transparent widget in front of video area to receive and redirect QMouseEvent to your custom dock. Though this is not a beautiful solution... How to create such widget is described here.

Qt - Draw a fully transparent window in Windows without using WA_TranslucentBackground

I need to draw transparent window (either QLabel or QFrame or QWidget), but without using WA_TranslucentBackground. The reason for that is that the windows will contain other child widgets rendered through OpenGL, and using that property makes those windows invisible on Windows, as documented here. This works fine in Mac though, I need a different solution on Windows only, as it does not work there. I tried this: setting a blank pixmap. But it still shows up with a grey background:
#include <QApplication>
#include <QLabel>
#include <QBitmap>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel l;
l.setWindowFlags(Qt::FramelessWindowHint);
QPixmap p("");
l.setPixmap(p);
l.setScaledContents(true);
l.resize(300, 500); //just to test my idea
l.setMask(p.scaled(l.width(),l.height(),Qt::IgnoreAspectRatio,
Qt::SmoothTransformation).mask());
l.show();
return a.exec();
}
Can anyone suggest any other means of achieving this on Windows, i.e a fully transparent window? Platform - Qt 5.3.1, 32 bit.
P.S - It need not behave like translucent window, i.e where the background can be clicked through the transparent parts of a widget rendered though WA_TranslucentBackground. Here as long as it is transparent it will be okay, it need not be clickable 'through'.
I am on Windows (Qt 5) and use the following to create a Semi-Transparent Widget:
setWindowOpacity(0.6);
setStyleSheet("QWidget{background: #000000}")
It should work if you set the opacity to zero.
I use this together with the Windows flags "framelessWindow" and "Tool" to darken the background of the screen.
transparency can be achieved by enabling blur behind window and by setting windows attribute to WA_TranslucentBackground
setAttribute(Qt::WA_TranslucentBackground);
QtWin::enableBlurBehindWindow(this);
required , cpp include : include<QtWin>, project file include : QT += winextras
the method enableBlurBehindWindow() has two more overload ,you can look those on this documentation
For child widgets you can use
setStyleSheet("background:transparent");
Unfortunately this is not possible on Windows. You can set transparency for widget with color with alpha-channel like this: setStyleSheet("background-color: rgba(255,0,0,50%);");. But whis is doesn't work for top level widget until you set WA_TranslucentBackground. Without this flag alpha-channel doesn't work and you get black window. So the only solution is use WA_TranslucentBackground. And then do OpenGL painting like Qt documentation says:
To work around this issue you can either just use Qt to render
everything and not OpenGL, or you can render the OpenGL into a pixmap
and draw that onto your widget instead.

QT: Frameless window not animating

i need some help for my current project named "RibbonUI".
As the project name suggest, i want to implement the MS RibbonUI like in Office 2013 in QT - most stuff is working nice but i need to know something about the Qt::FramelessWindowHint.
I have subclassed the QMainWindow and added the enum value Qt::FramelessWindowHint to override the default window decoration. The buttons are implemented fine - i can minimize, maximize and close my frameless window, but the window is not animated when minimizing/maximizing/restore the window from the taskbar.
Do i have to implement the animation by myself or can i use a window manager hint or something else?
Here is a screenshot from my current work:

QML frameless window supporting aero snap

I have made an QML application using a frameless window and implemented actions like dragging and resizing by myself. But this way the application doesn't support native window manager features like windows aero snap or the Gnome window manager features. So I searched and found this where someone found a way to support them in a frameless window using the win32 API. But is there a way to use this with a QML application or another way to use the native window manager features?
I initialize the window from C++ with this code:
QQmlApplicationEngine engine(QUrl("qrc:/qml/main.qml"));
QObject *topLevel = engine.rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
window->setFlags(window->flags() | Qt::FramelessWindowHint);
if ( !window ) {
qWarning("Error: Your root item has to be a Window.");
return -1;
}
window->show();
EDIT: I would also like to use the native window manager drop shadow like in the example I have linked to, if possible.
EDIT:
I have a second problem: Following #Kuba Obers instructions I got it to work how it was intended to. But now I have the problem, that when I resize or move it Qt leaves an undrawn area with the size of the frame.
The winapi window handle is provided by window->winId():
HWND handle = window->winId();
You can pass this handle to native functions.
To filter the WM_NCCALCSIZE message, you need to implement a native event handler by subclassing QAbstractNativeEventFilter, and install an instance of it on the application by calling qApp->installNativeEventFilter(myFilter).

How would you build a windowless application with C++/Qt5?

How would you build a windowless application with C++/Qt5? Do I have to use QDialog or QWidget?
For example, Launchy has no window border and the background around the text box is transparent.
I think that's what you're looking for :
http://qt-project.org/doc/qt-4.8/widgets-shapedclock.html
This is a tutorial on how to make a shaped and borderless window with Qt.
It's for Qt4.8 though, i think it should work on Qt5.
EDIT : Found the Qt5.0 version : http://qt-project.org/doc/qt-5.0/qtwidgets/widgets-shapedclock.html
Use a QWidget with Qt::SplashScreen or Qt::FramelessWindowHint. Check all the other window flags.