QT Switching window transparency off - c++

I have following problem. I switched on the transparency of the QWidget (top-level) with
setAttribute(Qt::WA_TranslucentBackground);
and it is all good. The window (QWidget) had a system shadow around it and it dissapeared and it was good as well. However now I need to switch the transparency off and it can be done with:
setAttribute(Qt::WA_TranslucentBackground, false);
But I would like to have the shadow back, but it doesn't appear. I'm using linux. Do you know how to enable the shadow?

Related

Qt widget blurred semitransparent background on Linux

Working with widgets, c++ and Linux
need something kind of:
this
but no borders and custom title.
Search for a few days, but nothing.
For now, there is a widget with setWindowFlags(Qt::FramelessWindowHint); and a peace of qss for semitransparent background. How can I blur it? Is is possible at all?
I do not think this can be done with Qt. Blurring can be done using https://doc.qt.io/qt-5/qgraphicsblureffect.html but it is only limited to the widgets painted by Qt. Which the underlying background is not, even if you manage to make your widgets transparent or semitransparent. Painting the background is always the business of the operating system (or window manager) and not the business of your application Qt.
You can certainly try to do some extreme hacking like grabbing the active screen before your window is displayed (see How to capture the current screen image using Qt?) then getting certain rectangle content of the image, which corresponds to the background of your window, then paint it blurred to the background of your application and then update it everytime you move or resize your window... But anyway, even if you manage this, this background will be static and not dynamic.
I recommend that you abandon the idea of blurry background and leave this function to the window manager and the operating system.

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.

How to create a borderless window with titlebar in windows c++

I am trying to create a Direct3D app that is operating in windowed mode with a title bar and minimize/quit button. However, I'd really like to be able to axe the border around the window.
I am looking to do this because it looks pretty cheesy on dual monitors when the app is filling the primary monitor horizontally (with room to move the app vertically), but its window border overflows onto the secondary screen. I've tried a bunch of combinations of setwindowlong with GWL_STYLE and GWL_EXSTYLE, but can't seem to make headway unless I disable the title bar.
I've seen a bunch of apps that are borderless however they seem to emulate the title bar rather than using the built in one provided by Microsoft.
Thanks for any suggestions.
You can't remove the border and keep the titlebar AFAIK.
You can reimplement the titlebar by using WM_NCHITTEST but you still need to draw it yourself which would not be a bad idea if you want your D3D app to look its best.
Visual Studio, last time I checked, achieves its border with transparent layered windows standing behind the primary one. They are the shadows you see.

Drop shadow on masked window

In my project, I have a window that has been masked with setMask(QRect()). It works fine, but the shadow that the Window Manager leaves is gone. I definitely want that drop shadow effect on my program.
At first, I moved all of my objects into a single widget and had that widget cast a box shadow onto the MainWindow. Then I made the MainWindow transparent with setAttribute(Qt::WA_TranslucentBackground, true) and setWindowFlags(Qt::FramelessWindowHint). This did the job, however, having a frameless window caused many issue that I can't seem to fix. Namely, this: https://stackoverflow.com/questions/31418494/qtframelesswindowhint-window-cant-be-recorded-with-obs
If I just do setAttribute(Qt::WA_TranslucentBackground, true) or set the style sheet, the background becomes black, not transparent.
So my question is, how do I make the MainWindow transparent without removing the frame? Or how do I cast a shadow when using setMask?
Thanks for your time.

OpenGL Non-exclusive Fullscreen Mode (A.K.A. Fullscreen Borderless Window)

I'm trying to get support for a fullscreen borderless window working but none of the information I've found helps.
Regardless of whether or not the window is set as WS_EX_TOPMOST, the window will always be in exclusive fullscreen mode. I've checked the window styles in games using fullscreen borderless window mode with WinSpy++ and the styles I'm using are identical.
I know it's in exclusive fullscreen mode because WDM stops rendering the little aero preview thing for my window. I also get that desktop flicker from focusing and unfocusing the window.
The only way I've been able to get a behaviour similar to what I want is by tricking windows into thinking I don't want fullscreen mode. The way I do that is by adjusting the window position by 1px so that it doesn't match the position and size of the screen. This stops Windows from automatically turning on exclusive fullscreen mode.
I know in DirectX the solution to this is simply to create the device with the windowed flag set to true. However, I have never seen anything like that in OpenGL.
Edit as per first comment:
I'm not using any third party library for my windowing, just Win32 and OpenGL.
Edit:
I am using WS_POPUP as the window style. With this same window style in some DirectX tests I did, I can properly create a fullscreen borderless window or a fullscreen exclusive window by changing the 'windowed' property.
For hardware I'm using a GTX690 with the latest drivers on Win7 x64.
Use PFD_SUPPORT_COMPOSITION in the PIXELFORMATDESCRIPTOR of ChoosePixelFormat/SetPixelFormat.
See The OpenGL Pipeline Newsletter - Volume 003