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

WA_TranslucentBackground doesn't work for native child widget on Windows

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.2
    • Fix Version/s: None
    • Component/s: QPA: Windows
    • Labels:
      None
    • Platform/s:
      Windows

      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)".

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              owolff Oliver Wolff
              Reporter:
              mingxiang Mingxiang Xu
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes