Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-102145

BUG about Qt::WA_TranslucentBackground in QT

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.9.9, 5.13.2, 5.15.2
    • Fix Version/s: None
    • Component/s: QPA: Windows
    • Labels:
      None
    • Environment:
      windows 10 ,msvc2019,QT 5.9.9
    • Platform/s:
      Windows

      Description

      I want to put a transparent window into the windows desk icon layer,Some problems were encountered during this process. The widget works fine on the desktop, but when placed on the desktop icon layer, it is completely transparent. But actually I used painter to draw a background that is not completely transparent, and some sub widgets in it are not drawn normally. After some testing, the invisible widget can respond to mouse events, but it is not displayed, which is very strange. I wrote a simple example to reproduce the problem. 

      #include "mainwindow.h"
      #include <windows.h>
      #include <windowsx.h>
      #include "ui_mainwindow.h"
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          setAttribute(Qt::WA_TranslucentBackground);
          setWindowFlags(Qt::FramelessWindowHint);
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      BOOL enumWindowFindDesktopIconWindow(HWND hwnd, LPARAM lParam)
      {
          long wflags = GetWindowLong(hwnd, GWL_STYLE);
          if (!(wflags & WS_VISIBLE))
              return TRUE;
          HWND sndWnd;
          if (!(sndWnd = FindWindowEx(hwnd, NULL, L"SHELLDLL_DefView", NULL)))
              return TRUE;
          HWND targetWnd;
          if (!(targetWnd = FindWindowEx(sndWnd, NULL, L"SysListView32", L"FolderView")))
              return TRUE;
          HWND* resultHwnd = (HWND*)lParam;
          *resultHwnd = targetWnd;
          return FALSE;
      }
      
      
      HWND findDesktopIconWindow()
      {
          HWND resultHwnd = NULL;
          EnumWindows((WNDENUMPROC)enumWindowFindDesktopIconWindow, (LPARAM)&resultHwnd);
          return resultHwnd;
      }
      void setWindowToIconLayer(HWND winID)
      {
      
          HWND desktopHwnd = findDesktopIconWindow();
          if (!desktopHwnd)
              return ;
          SetParent(winID, desktopHwnd);
      }
      
      void MainWindow::on_pushButton_clicked()
      {
          setWindowToIconLayer((HWND)this->winId());
      }

      This is a new project and a button is placed in the mainwindow,click the button to place the widget on the icon layer

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            owolff Oliver Wolff
            Reporter:
            keyboardman mms nn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes