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

WA_TranslucentBackground doesn't work for native child widget on Windows

    XMLWordPrintable

Details

    • Windows
    • G&UI Finishing 2023

    Description

      https://github.com/qt/qtbase/blob/5.15.2/src/plugins/platforms/windows/qwindowsbackingstore.cpp#L92-L106

      // Windows with alpha: Use blend function to update. 
      QRect r = QHighDpi::toNativePixels(window->frameGeometry(), window); 
      QPoint frameOffset(QHighDpi::toNativePixels(QPoint(window->frameMargins().left(), window->frameMargins().top()), 
                                                  static_cast<const QWindow *>(nullptr))); 
      QRect dirtyRect = br.translated(offset + frameOffset); 
       
      SIZE size = {r.width(), r.height()}; 
      POINT ptDst = {r.x(), r.y()}; 
      POINT ptSrc = {0, 0}; 
      BLENDFUNCTION blend = {AC_SRC_OVER, 0, BYTE(qRound(255.0 * rw->opacity())), AC_SRC_ALPHA}; 
      RECT dirty = {dirtyRect.x(), dirtyRect.y(), 
                    dirtyRect.x() + dirtyRect.width(), dirtyRect.y() + dirtyRect.height()}; 
      UPDATELAYEREDWINDOWINFO info = {sizeof(info), nullptr, &ptDst, &size, 
                                      m_image->hdc(), &ptSrc, 0, &blend, ULW_ALPHA, &dirty}; 
      const BOOL result = UpdateLayeredWindowIndirect(rw->handle(), &info); 
      

      The parameters to UpdateLayeredWindowIndirect are incorrect. Currently, this code only works when the window's position is (0, 0).

      When updating the whole HWND:
      ptSrc is the top-left in m_image. It should be "offset + frameOffset" instead of "{0, 0}".
      dirty is the rectangle in HWND's client area. It's not the rectangle in m_image. It should be "br" instead of "br.translated(offset + frameOffset)".
      pptDst should be NULL. The flush method should only update the content of the window, instead of changing the position. The position is computed incorrectly for child window when HDPI is on.

      Attachments

        1. QTBUG-105537_qt6.cpp
          0.6 kB
        2. QTBUG-105537.cpp
          0.6 kB
        3. QTBUG-105537.manifest
          0.7 kB

        Issue Links

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

          Activity

            People

              owolff Oliver Wolff
              mingxiang Mingxiang Xu
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes