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. Transparency with QOpenGLWidget
Forum Update on Monday, May 27th 2025

Transparency with QOpenGLWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 489 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.
  • J Offline
    J Offline
    j_omega
    wrote on last edited by j_omega
    #1

    I have made a widget which inherits from QOpenGLWidget. In the paint event, I call the following code:

    QColor black70 = Qt::black;
    
    black70.setAlphaF(0.3);
    QBrush brush(painter.brush());
    brush.setColor(black70);
    brush.setStyle(Qt::SolidPattern);
    painter.setBrush(brush);
    QPen pen(painter.pen());
    pen.setColor(Qt::white);
    pen.setWidthF(0.5);
    painter.setPen(pen);
    
    QRectF myBox(QPointF(0, -100), QPointF(60, 100));
    painter.drawRect(myBox);
    

    In this code, I specifically set the opacity to 30%.

    This widget is drawn on top of another widget. I have found that during the first paint, the opacity renders correctly, but on subsequent paints, the box turns darker and darker until it is finally completely black (no transparency).

    How should I handle this? I don't have the problem when using QWidget instead of QOpenGLWidget.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The questions would rather be:

      • Why use a QGLWidget if doing normal painting ?
      • Why use QGLWidget at all ? QOpenGLWidget is recommended for new development
      • What version of Qt are you using ?
      • What OS are you running ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • J Offline
        J Offline
        j_omega
        wrote on last edited by j_omega
        #3

        Sorry, I mispoke in the first post. I am using QOpenGLWidget. I have modified the post appropriately.

        I am targeting an embedded system with limited processor resources, so I was hoping to off-load all of the graphics work to the graphics accelerator. My understanding from this article and this example is that QWidget uses a software rasterizer while QOpenGLWidget uses hardware acceleration.

        This was last tested on Qt 5.10 on Windows 10. I have not tested this aspect on the embedded platform yet. The embedded platform is running Linux 4.14.

        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