Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Transparency does not work on Qt 5-5.15.2-1



  • I am running Qt 5-5.15.2-1 on a Mageia 8 platform, and since their QT update on or about December 8 the transparency on my Qt Designer applications has stopped working. The background for all of them is now an opaque, black rectangle. These applications were running fine until the upgrade.

    To trouble shoot the problem, I created a simple desktop template program in Qt Designer and attempted to make the window transparent by adding the line

        this->setAttribute(Qt::WA_TranslucentBackground);
    

    to the mainwindow.h code. Here is the code for the entire mainwindow class.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        // Make the MainWindow transparent
        this->setAttribute(Qt::WA_TranslucentBackground);
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    The only change I made to the template was to set Qt::WA_TranslucentBackground true. When I run the program, I get a window with a black background as shown in the following image.

    TransparencyOnQt5-5_15_2-1.png

    If I remove the line of code that sets Qt::WA_TranslucentBackground true, I get the expected result, a window with a neutral gray background, as shown in the following image:

    TransparencyOffQt5-5_15_2-1.png

    To confirm that my program should make the background transparent, I ran it on my Mageia 7 computer, running Qt 5-5.12.6-4, with transparency set and I get the expected transparent background, as shown below.

    TransparencyOnQt5-5_12_6-4.png

    These are two different computers with two different graphics cards. I do not know if that is relevant or not.

    Here is the system information for the one that fails:

    System:    Host: localhost Kernel: 5.10.1-desktop-1.mga8 x86_64 bits: 64 Desktop: KDE Plasma 5.20.4 Distro: Mageia 8 mga8 
    Machine:   Type: Desktop Mobo: ASUSTeK model: P5G41T-M LX PLUS v: Rev X.0x serial: <superuser/root required> 
               BIOS: American Megatrends v: 0502 date: 10/21/2011 
    CPU:       Info: Dual Core Intel Core2 Duo E7300 [MCP] speed: 2478 MHz 
    Graphics:  Device-1: NVIDIA G94 [GeForce 9600 GT] driver: nvidia v: 340.108 
               Display: x11 server: Mageia X.org 1.20.10 driver: nvidia,v4l resolution: 1920x1080~60Hz 
               OpenGL: renderer: GeForce 9600 GT/PCIe/SSE2 v: 3.3.0 NVIDIA 340.108 
    

    Here is the system information for the one that works:

    System:    Host: linuxmain Kernel: 5.7.19-desktop-3.mga7 x86_64 bits: 64 Desktop: KDE Plasma 5.15.4 Distro: Mageia 7 mga7 
    Machine:   Type: Desktop System: ASUS product: All Series v: N/A serial: <root required> 
               Mobo: ASUSTeK model: Z97-A-USB31 v: Rev 1.xx serial: <root required> UEFI [Legacy]: American Megatrends v: 2501 
               date: 06/24/2015 
    CPU:       Quad Core: Intel Core i5-4590 type: MCP speed: 1200 MHz min/max: 800/3700 MHz 
    Graphics:  Device-1: NVIDIA GM107 [GeForce GTX 750 Ti] driver: nvidia v: 430.64 
               Display: x11 server: Mageia X.org 1.20.9 driver: nvidia,v4l resolution: 1920x1080~60Hz, 1920x1080~60Hz 
               OpenGL: renderer: GeForce GTX 750 Ti/PCIe/SSE2 v: 4.6.0 NVIDIA 430.64 
    

    I have tried some other tricks that are mentioned on the web to no avail, e.g.

        this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
        // Make the MainWindow transparent
        this->setAttribute(Qt::WA_TranslucentBackground);
        this->setAttribute(Qt::WA_NoSystemBackground);
        this->setAttribute(Qt::WA_PaintOnScreen);
        this->setStyleSheet("background-color: transparent");
    

    The PaintOnScreen setting caused the program to capture the screen background in the window, which then followed the window around when I moved it... not exactly what I was looking for.

    Has anyone else seen this problem? Maybe it is a new incompatibility between this old system and the new Qt.

    Any help or ideas about how to make transparency work again would be welcome.

    Thanks,
    Banjo
    (_)=='=~



  • I think that I have absolved Qt from any responsibility for the transparency not working on my system.

    I downloaded an example program from

    https://github.com/datenwolf/codesamples/blob/master/samples/OpenGL/x11argb_opengl/x11argb_opengl.c

    which I found at StackOverflow here

    https://stackoverflow.com/questions/4052940/how-to-make-an-opengl-rendering-context-with-transparent-background.

    The program creates a window with a transparent background using GLX. I compiled this on my Mageia 7 system and it does create a window with a transparent background as expected. When I ran the program that I compiled on Mageia 7 on the Mageia 8 computer it made the window opaque black.

    So I compiled the same code on my Mageia 8 computer, and the background is a black rectangle. No change to the code.

    The program uses GLX to open the window, hence it does not use Qt at all, That indicates that the problem lies in the code that underpins the Qt software, not with Qt.

    This would also explain why transparency also does not work in conky anymore either.

    I suspect that it is a disconnect between X11 and the Nvidia driver. The other graphics seem to work OK.

    So I am marking this issue fixed. Although I still have the issue, as far as Qt is concerned it has been resolved.



  • For anyone who finds this later because they have the same issue, I have actually found a workaround that fixes the problem. Evidently the back end of the Plasma compositor defaults to OpenGL 2.0, and that is not working anymore. If I set the compositor backend to XRender the transparency works again.

    The workaround is

    System Settings => Display and Monitor => Compositor

    Then, for the Rendering backend: select XRender.



  • I met the same problem on Windows10.

    GPU:
    Intel(R) HD Graphics 630
    AMD Radeon RX 550

    CPU:
    Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz 3.00 GHz

    OS:
    Windows 10 Education 21H1 19043.1237

    I have tried all the methods I can find and none of them work on Qt5-5.15.2-1. So I am using 5.9.9 instead...And it just works as what I expect.



  • @Banjo-0 @LadderOperator I am facing this issue on macOS, on Windows transparency works fine.
    Are you able to fix the issue.


Log in to reply