Search code examples
pythonwinapipyqt4aero

Python/PyQT check if Aero enabled


As told here Qt: Erase background (Windows Aero Glass), I'm using WA_TranslucentBackground to have a glass background on my QMainWindow: on Windows 7 (Aero enabled) it works well, but on Linux (KDE4) I get a black background, I haven't tried on a PC with Aero disabled, or maybe older than Vista.

Is there a way to check if Aero is available and enabled, so I can set WA_TranslucentBackground only if it's enabled, and keep the standard background on Linux and Windows without Aero?

It seems that Windows API's DwmIsCompositionEnabled does the job, but I cannot find how to call it from Python, also taking in account that it may not exist on pre-Vista versions.


Solution

  • You can try something like the following. It should handle being run on non-Windows platforms, and also the absence of the DwmIsCompositionEnabled function:

    import ctypes
    
    def is_aero_enabled():
        try:
            b = ctypes.c_bool()
            retcode = ctypes.windll.dwmapi.DwmIsCompositionEnabled(ctypes.byref(b))
            return (retcode == 0 and b.value)
        except AttributeError:
            # No windll, no dwmapi or no DwmIsCompositionEnabled function.
            return False
    

    On my Windows 7 machine, this returns True.