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 + DirectX: Invisible Window with WA_TranslucentBackground and WA_UpdatesDisabled
QtWS25 Last Chance

Qt + DirectX: Invisible Window with WA_TranslucentBackground and WA_UpdatesDisabled

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 61 Views
  • 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.
  • F Offline
    F Offline
    froxy
    wrote last edited by
    #1

    Hello,

    I'm working on a Qt application where I'm using a QWidget (ui.renderSurface) to render content using DirectX. I'm retrieving the HWND of this widget to use with my DirectX pipeline.

    I'm encountering an issue when trying to make the main window (QMainWindow) translucent and disable Qt's updates on it simultaneously.

    My goal is to have a custom-rendered area within a window that might potentially have some level of transparency or custom styling, while handling the rendering entirely with DirectX.

    Here's the relevant part of my window constructor:

    RemoteDesktopWindow::RemoteDesktopWindow(int id, RemoteSessionWindow* parentRemoteSessionWindow)
    	: QMainWindow(Q_NULLPTR)
    	, id{ id }
    	, parentRemoteSessionWindow{ parentRemoteSessionWindow }
    {
    	this->setAttribute(Qt::WA_NoSystemBackground);
    	this->setAttribute(Qt::WA_TranslucentBackground); 
    	this->setWindowFlags(Qt::FramelessWindowHint); 
    	ui.setupUi(this);
    
    	ui.renderSurface->setStyleSheet("background-color: black;"); 
    
    	ui.centralWidget->setStyleSheet("border-radius: 8px; background-color: transparent;");
    	ui.backgroundPanel->setStyleSheet("border-radius: 8px; background-color: yellow;");
    
    	this->setAttribute(Qt::WA_UpdatesDisabled); 
    	setMouseTracking(true);
    }
    
    HWND RemoteDesktopWindow::GetRenderWindowHWND() {
    	return reinterpret_cast<HWND>(ui.renderSurface->winId()); // Getting HWND for DirectX
    }
    

    When both this->setAttribute(Qt::WA_TranslucentBackground); and this->setAttribute(Qt::WA_UpdatesDisabled); are active on the QMainWindow, the entire window is invisible.

    If I comment out this->setAttribute(Qt::WA_UpdatesDisabled);, the window becomes visible (and translucent), but my DirectX rendering on ui.renderSurface does not appear – the render surface remains black (or whatever its stylesheet background is).

    It seems there's a conflict or specific interaction between WA_TranslucentBackground and WA_UpdatesDisabled when combined with custom rendering using a native handle.

    Has anyone encountered a similar issue or can explain why setting both WA_TranslucentBackground and WA_UpdatesDisabled makes the window invisible? More importantly, how can I achieve a translucent window with custom rendering on a specific widget using its HWND?

    Any guidance or alternative approaches would be greatly appreciated!

    Thanks in advance.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      CassD
      wrote last edited by
      #2

      Hi

      I didn't have that particular issue but had one related to WA_TranslucentBackground recently : so it has to be cumulated with FrameLessWindowHint, and for my case I also need the permenent stay on top property. If I add the stay on top hint to translucent and frameless, the window becomes fully opaque.

      If you need opaque components on a transparent window (which is what I was looking for), you might be screwed. Otherwise, you might want to try QWidget::windowOpacity, which is simplier to handle and doesn't suffer flags incompatibilities. I haven't tested it on QtWidgets, but in a QtQuick Window it works without flags (and on top of that a frameless window is more problematic in my case). There seems to be some incompatibility among window flags and attributes, at least for windows but I didn't find any doc from windows about that. I didn't insist.

      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