Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT widgets and transparency
Forum Updated to NodeBB v4.3 + New Features

QT widgets and transparency

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shwong2002
    wrote on last edited by
    #1

    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);

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      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!

      Greetz, Jeroen

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved