QT widgets and transparency



  • I have two custom QT widgets (basically opengl QT widgets) inside a QMainWindow.

    I want the QMainWindow to be transparent, but I still want what is rendered in the Opengl widgets to be opaque.

    I cannot seem to do this. When I set the main window as transparent, the widgets become transparent too even if I modify the attributes, background roll, and AutobackgroundFill of the widget. In this case, I basically have everything transparent -- here is my code, which is in the constructor of the QMainWindow. Any ideas of what is wrong? Thanks!

    //try to make the window transparent
    setAttribute(Qt::WA_TranslucentBackground); //this line makes everything dissapear!!!
    setStyleSheet("background:transparent;");
    setWindowFlags(Qt::FramelessWindowHint);

    ui.glWidgetChai->setAutoFillBackground(true);
    ui.glWidgetChai->setAttribute(Qt::WA_OpaquePaintEvent);
    ui.glWidgetChai->setBackgroundRole(QPalette::Button);

    //ui.layoutTopView->addWidget(glWidgetChai2);
    ui.glWidgetChai2->setAutoFillBackground(true);
    ui.glWidgetChai2->setAttribute(Qt::WA_OpaquePaintEvent);
    ui.glWidgetChai2->setBackgroundRole(QPalette::Button);



  • Hi, The stylesheet/code you posted is almost unreadable. Please place it within Code block. The stylesheet is a very powerfull option for widgets. I also encountered a similar problem. The stylesheet of the parent will also be the stylesheet for the widgets. When you want a stylesheet only active for a single type of widget you could try the following:
    @setStylesheet(QMainWindow{border-image:none});@
    This will set the border image only for the QMainWindow and if your child widgets will not be (or inherit) a QMainWindow there stylesheets will be left unchanged.
    Hope this helps, but to help you even better, place the code in a code block please.
    Happy coding!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.