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. Not getting correct blending when using QOpenGLWidget and a translucent window
Forum Update on Monday, May 27th 2025

Not getting correct blending when using QOpenGLWidget and a translucent window

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 1 Posters 231 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.
  • G Offline
    G Offline
    Guy Gizmo
    wrote on 28 Aug 2024, 23:49 last edited by Guy Gizmo
    #1

    I'm trying to create a translucent window with a QGraphicsScene using OpenGL as its backend, using Qt 6.2.3 in macOS 13.

    I've got images rendering into it, but transparency is not working correctly. The window is indeed translucent, and shapes that I add to the QGraphicsScene with an alpha value of less than one are partially transparent, but rather than doing a simple alpha blend, it does a blend that seems equivalent to Photoshop's "screen" blending, where dark colors take on the color of the layer being blended into it, and light colors are unaffected.

    I've tried setting the correct blending function using glBlendFunc in both the paintGL method of my QOpenGLWidget and in my QGraphicView drawBackground method, but it doesn't have any effect.

    To give an illustration of the sort of wrong blending I'm getting, here's what happens if open my translucent window over a browser window, and I call glClear in my drawBackground method with a clear color of (1.0, 0.0, 0.0, 0.0), a color which ought to be 100% transparent but instead has this effect:

    Screenshot 2024-08-28 at 7.28.27 PM.png

    What do I need to do to just get regular alpha blending?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Guy Gizmo
      wrote on 29 Aug 2024, 15:40 last edited by
      #3

      I've sorted it out: I had a feeling this might have to do with premultiplied alpha, and it turns out that the macOS compositor requires all windows to premultiply their alpha before compositing. All I needed to do was change my calls to glColor4f so that the red, green, and blue values were multiplied by the alpha value. I'll also need to make sure that any textures I use are premultiplied.

      1 Reply Last reply
      1
      • G Offline
        G Offline
        Guy Gizmo
        wrote on 29 Aug 2024, 15:32 last edited by
        #2

        I've done a bit more digging into this, and I've found that this issue happens without using QGraphicsView, so that aspect of this is irrelevant. I can reproduce the issue by just using a QOpenGLWidget in a translucent window.

        Any drawing I perform using QPainter in the widget's paintGL method will have correct transparency and blend properly with the windows beneath it. However, any drawing I do between calls to QPainter::beginNativePainting() and QPainter::endNativePainting() with pure GL calls will have this transparency issue. I'm still not sure why, though!

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Guy Gizmo
          wrote on 29 Aug 2024, 15:40 last edited by
          #3

          I've sorted it out: I had a feeling this might have to do with premultiplied alpha, and it turns out that the macOS compositor requires all windows to premultiply their alpha before compositing. All I needed to do was change my calls to glColor4f so that the red, green, and blue values were multiplied by the alpha value. I'll also need to make sure that any textures I use are premultiplied.

          1 Reply Last reply
          1
          • G Guy Gizmo has marked this topic as solved on 29 Aug 2024, 15:40

          1/3

          28 Aug 2024, 23:49

          • Login

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