📜 ⬆️ ⬇️

Creating a background blur below a window in Windows

Just yesterday, a topic was published on the Qt developer blogs, which described how you can create the effect of blurring the background under the application window in Windows Vista and Windows 7.


Since Qt 4.5, we have added transparency support, which can be enabled by setting the Qt :: WA_TranslucentBackground attribute. Unfortunately, according to the documentation, this will only work on Windows if you explicitly remove the window decoration.
Starting with Windows Vista, Microsoft introduced the DWM (Desktop Window Manager) api , where you can turn on the blur effect under the window of your application. Unfortunately, Qt does not yet have an API covering these features, but using the above attribute in combination with several native API calls you can already get this effect.


')
To facilitate, I created a convenient mechanism for making the necessary calls, which you can include in your existing code. I note that the code must be compiled on other platforms:

bool QtWin::isCompositionEnabled()
bool QtWin::enableBlurBehindWindow(QWidget *widget, bool enable)
bool QtWin::extendFrameIntoClientArea(QWidget *widget, int left, int top, int right, int bottom)
QColor QtWin::colorizationColor()


* This source code was highlighted with Source Code Highlighter .


You can make a widget blurred by calling the enableBlurBehindWindow method or extendFrameIntoClientArea with indents set. In both cases, you can easily modify the background of the widget. The colorizationColor method returns the color used for coloring windows in the system.

To demonstrate the effect, I made (one more!) 200-line Qt browser (original: 200-line Qt browser). It has a modified style sheet with translucent widgets. You can also see how you can make segmented arrow buttons using just a couple of style sheets.

The code and working example can be taken from here .
The code is separately available here .



Happy programming!

Source: https://habr.com/ru/post/69820/


All Articles